正しくはこう
(define (<=/cps x y k) (k (<= x y)))
(define (-/cps x y k) (k (- x y)))
(define tarai-cps
(lambda (x y z k)
(<=/cps x y
(lambda (b)
(if b
;ここが違う
(k y)
(-/cps x 1
(lambda (x2)
(tarai-cps x2 y z
(lambda (t1)
(-/cps y 1
(lambda (y2)
(tarai-cps y2 z x
(lambda (t2)
(-/cps z 1
(lambda (z2)
(tarai-cps z2 x y
(lambda (t3)
;ここも
(tarai-cps t1 t2 t3 k))))))))))))))))))
(time (tarai-cps 10 5 0 (lambda (x) x)))
っで、ベンチマークの結果。Petite Chez Scheme 7.9.4
(time (tarai-org 10 ...))
no collections
16 ms elapsed cpu time
0 ms elapsed real time
0 bytes allocated
(time (tarai-cps 10 ...))
10 collections
125 ms elapsed cpu time, including 0 ms collecting
0 ms elapsed real time, including 0 ms collecting
44600752 bytes allocated, including 42111448 bytes reclaimed
(time (tarai-anf 10 ...))
7 collections
78 ms elapsed cpu time, including 0 ms collecting
0 ms elapsed real time, including 0 ms collecting
29505120 bytes allocated, including 29499488 bytes reclaimed
(time (tarai-lambda 10 ...))
7 collections
78 ms elapsed cpu time, including 0 ms collecting
0 ms elapsed real time, including 0 ms collecting
29505120 bytes allocated, including 29490760 bytes reclaimed
Gauche 0.9
;(time (tarai-org 10 5 0))
; real 0.016
; user 0.015
; sys 0.000
;(time (tarai-cps 10 5 0 (lambda (x) x)))
; real 0.453
; user 0.407
; sys 0.047
;(time (tarai-anf 10 5 0))
; real 0.031
; user 0.031
; sys 0.000
;(time (tarai-lambda 10 5 0))
; real 0.422
; user 0.375
; sys 0.047
圧倒的じゃないか。。。orzどう考えてもなしの方向っぽいです、本当に(ry
No comments:
Post a Comment