(define sumi
  (lambda (term a next b)
    (define iter
      (lambda (a result)
        (if (> a b)
            result
            (iter (next a) (+ result (term a))))))
    (iter a 0)))

chez和ikarus的表现完全不一样..

chez:

> (time (sum (lambda (x) (* 2 x)) 0 (lambda (x) (+ x 1)) 3800011))
(time (sum (lambda (...) ...) ...))
    65 collections
    1176 ms elapsed cpu time, including 322 ms collecting
    1177 ms elapsed real time, including 318 ms collecting
    275239064 bytes allocated, including 267307688 bytes reclaimed
14440087400132

> (time (sumi (lambda (x) (* 2 x)) 0 (lambda (x) (+ x 1)) 3800011))
(time (sumi (lambda (...) ...) ...))
    15 collections
    932 ms elapsed cpu time, including 3 ms collecting
    934 ms elapsed real time, including 5 ms collecting
    60092864 bytes allocated, including 146771696 bytes reclaimed
14440087400132

迭代不迭代差别不大..

 

相反,ikarus很有差别

> (time (sum (lambda (x) (* 2 x)) 0 (lambda (x) (+ x 1)) 3800011))
running stats for (sum (lambda (x) (* 2 x)) 0 (lambda (x) (+ x 1)) 3800011):
    29 collections
    6600 ms elapsed cpu time, including 5740 ms collecting
    6762 ms elapsed real time, including 6156 ms collecting
    119417416 bytes allocated
14440087400132

 

> (time (sumi (lambda (x) (* 2 x)) 0 (lambda (x) (+ x 1)) 3800011))
running stats for (sumi (lambda (x) (* 2 x)) 0 (lambda (x) (+ x 1)) 3800011):
    14 collections
    460 ms elapsed cpu time, including 248 ms collecting
    513 ms elapsed real time, including 365 ms collecting
    60429480 bytes allocated
14440087400132

 

 

Posted on 2013-03-08 16:28  ASOCS  阅读(109)  评论(0编辑  收藏  举报