You can read the story up to the build up here .
Now IronScheme comes to the party.
(define (fib n)
(define (fibr n a b)
(if (= n 0)
a
(fibr (-n 1) b (+ a b))))
(fibr n 0 1))
(define (test n)
(do
((i 0 (+ i 1)))
((= i n) 'done)
(fib i)))
And the results:
> (time (test 4500)) 00:00:02.5623016 done
2.5 secs, eat this SBCL
Obviously IronScheme is completely tail-recursive. The only problem is the lack of big numbers, or rather the promotion to big numbers. I will work on it this weekend and post some updated numbers.
Out of curiosity, how much time would it take to print out the results of each call to fib? It looks like that’s what the SBCL implementation does. On my machine, the SBCL version with format took 11.376 sec of real time. Once I comment out the format call, it reports 0.0 sec of real time up.
But aren’t benchmarks fun?
By: Eric Rochester on November 30, 2007
at 1:47 pm
OK
Now I get 13.37 seconds with printing. Just had to implement some transitions for bignumbers (i am sure that helped a ‘little’).
By: leppie on November 30, 2007
at 10:45 pm
HAHA, by minimizing the console , I can get it down to 8.3 seconds :p
By: leppie on November 30, 2007
at 10:46 pm