igouy / yahoo.com wrote: > jzakiya / mail.com wrote: > > The Great Computer Language Shootout Benchmarks > > http://shootout.alioth.debian.org/ > > is using an incorrect fibonacci algorithm benchmark. > > While acknowledging the comments of Josef, Michael, Nikolai, Joel, > Michael, and E, we'll probably change the code for the Fibonacci > programs for the simple reason that we refer to the Mathworld > definition which uses F(0)=0, so it's more than a little confusing when > we don't use that definition for the programs :-) > > The original Shootout referred to this definition > http://cubbi.org/serious/fibonacci.html > > > Meanwhile Tcl programmers have actually been contributing programs to > Shootout - no wonder Tcl now looks so much better than Ruby! Great. Thanks. I joined the Shootout list yesterday and was notified, and see, the benchmark has been corrected to conform to the references. Below is a Ruby benchmark which identifies a faster implementation. =================================================================== require 'benchmark' include Benchmark def fib1(n) if n<2 then n else fib1(n-1)+ fib1(n-2) end end def fib2(n) n<2 ? n : fib2(n-1)+ fib2(n-2) end def fib3(n) if n>1 then fib3(n-1)+ fib3(n-2) else n end end def fib4(n) n>1 ? fib4(n-1)+ fib4(n-2) : n end n=20 bmbm(12) do |x| x.report("fib1") { n.times { fib1(25) } } x.report("fib2") { n.times { fib2(25) } } x.report("fib3") { n.times { fib3(25) } } x.report("fib4") { n.times { fib4(25) } } end =================================================================== The following times were generated from the above benchmark. 600Mhz Athlon K-7, 640MB, Mandrake 10.1 Official, Ruby 1.8.2 Rehearsal ----------------------------------------------- fib1 11.910000 0.010000 11.920000 ( 12.205975) fib2 11.990000 0.000000 11.990000 ( 12.246299) fib3 11.740000 0.000000 11.740000 ( 11.963777) fib4 11.500000 0.000000 11.500000 ( 11.736313) ------------------------------------- total: 47.150000sec user system total real fib1 11.900000 0.000000 11.900000 ( 12.133921) fib2 12.000000 0.000000 12.000000 ( 12.248496) fib3 11.740000 0.000000 11.740000 ( 11.955820) fib4 11.460000 0.000000 11.460000 ( 11.696977) The following times were generated from the above benchmark. 600Mhz Athlon K-7, 640MB, Win98, Ruby 1.8.2 Rehearsal ----------------------------------------------- fib1 18.290000 0.000000 18.290000 ( 18.290000) fib2 17.740000 0.000000 17.740000 ( 17.740000) fib3 19.890000 0.000000 19.890000 ( 19.890000) fib4 17.460000 0.000000 17.460000 ( 17.460000) ------------------------------------- total: 47.150000sec user system total real fib1 17.850000 0.000000 17.850000 ( 17.850000) fib2 17.470000 0.000000 17.470000 ( 17.470000) fib3 18.070000 0.000000 18.070000 ( 18.070000) fib4 17.470000 0.000000 17.470000 ( 17.470000) fib4 is fastest, which is faster than Shootout version fib1. Note: These versions produce the correct fibonacci sequence for all index values n (n=0,1,2,3,4,5...) Jabari Zakiya