竹内関数をsbclとclisp,gaucheで試す2011/07/28 07:16

竹内関数 たらい回し関数を SBCLとCLISPで試してみた
さすが コンパイルとインタープリタの差でた
試したのは一世代前のMacBooKPro

機種 ID: MacBookPro5,5
プロセッサ名: Intel Core 2 Duo
プロセッサ速度: 2.53 GHz
プロセッサ数: 1
合計コア数: 2
二次キャッシュ: 3 MB
メモリ: 8 GB
バス速度: 1.07 GHz

----SBCL
This is SBCL 1.0.50, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.

SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses. See the CREDITS and COPYING files in the
distribution for more information.
* (defun tarai (x y z)

(cond ((> x y)

(tarai

(tarai (1- x) y z)

(tarai (1- y) z x)

(tarai (1- z) x y) ))

(t y) ))

TARAI
* ( time (tarai 12 6 0 ))

Evaluation took:
0.154 seconds of real time
0.153368 seconds of total run time (0.153099 user, 0.000269 system)
99.35% CPU
387,547,892 processor cycles
1 page fault
0 bytes consed

12
* ( time (tarai 13 7 0))

Evaluation took:
1.110 seconds of real time
1.108753 seconds of total run time (1.108107 user, 0.000646 system)
99.91% CPU
2,797,826,047 processor cycles
0 bytes consed

13
* ( time (tarai 14 8 0))

Evaluation took:
8.462 seconds of real time
8.447085 seconds of total run time (8.442201 user, 0.004884 system)
99.82% CPU
21,331,537,918 processor cycles
0 bytes consed
----- CLISP
Welcome to GNU CLISP 2.49 (2010-07-07) <http://clisp.cons.org/>

Copyright (c) Bruno Haible, Michael Stoll 1992, 1993
Copyright (c) Bruno Haible, Marcus Daniels 1994-1997
Copyright (c) Bruno Haible, Pierpaolo Bernardi, Sam Steingold 1998
Copyright (c) Bruno Haible, Sam Steingold 1999-2000
Copyright (c) Sam Steingold, Bruno Haible 2001-2010

Type :h and hit Enter for context help.

[1]> (defun tarai (x y z)

(cond ((> x y)

(tarai

(tarai (1- x) y z)

(tarai (1- y) z x)

(tarai (1- z) x y) ))

(t y) ))
TARAI
[2]> ( time (tarai 12 6 0 ))
Real time: 14.376711 sec.
Run time: 14.353813 sec.
Space: 0 Bytes
12
[3]> ( time (tarai 13 7 0 ))
Real time: 104.95189 sec.
Run time: 104.774605 sec.
Space: 0 Bytes
13
[4]> ( time (tarai 14 8 0 ))
Real time: 807.9998 sec.
Run time: 798.4294 sec.
Space: 0 Bytes
14
ーーーーGauche
gosh> (define (tarai x y z)
(if (<= x y) y
(tarai (tarai (- x 1) y z)
(tarai (- y 1) z x)
(tarai (- z 1) x y))))
(time (tarai 12 6 0))tarai
gosh>
;(time (tarai 12 6 0))
; real 0.740
; user 0.740
; sys 0.000
12
gosh> (time (tarai 13 7 0))
;(time (tarai 13 7 0))
; real 5.392
; user 5.390
; sys 0.000
13
gosh> (time (tarai 14 8 0))
;(time (tarai 14 8 0))
; real 40.751
; user 40.740
; sys 0.010
14