[plt-scheme] Futures performance

From: Groshev Dmitry (a2alt at yandex.ru)
Date: Tue May 25 22:53:59 EDT 2010

What am I doing wrong? Here is the code and some tests:

(require scheme/future)
 
(define (fib n)
  (case n
    [(0) 0]
    [(1) 1]
    [else (let ((a (fib (- n 1))) 
                (b (fib (- n 2)))) 
            (+ a b))]))

(define (fibp n)
  (case n
    [(0) 0]
    [(1) 1]
    [else (let ((a (future (lambda () (fib (- n 1))))) 
                (b (future (lambda () (fib (- n 2)))))) 
            (+ (touch a) (touch b)))]))

> (time (fib 30))
cpu time: 546 real time: 539 gc time: 0
832040
> (time (fibp 30))
cpu time: 8986 real time: 7814 gc time: 391
832040


Posted on the users mailing list.