[Shootout-list] Fibonacci Numbers: unfair entries for ocaml
Pit Capitain
pit at capitain.de
Sun Apr 23 22:54:51 UTC 2006
Hi there,
I received a link to the Fibonacci Numbers test and had a brief look at the
submissions. I think the top two entries (ocaml and ocamlb) don't implement the
same algorithm as the others I looked at. They calculate the result using a new
function with 3 arguments having a complexity of O(n).
For comparison, here's the equivalent modification of the Ruby entry:
# original
def fib(n)
if n < 2 then
1
else
fib(n-2) + fib(n-1)
end
end
# the "ocaml way"
def fib2(n)
def fiby(x, f0, f1)
if x == 0
f1
else
fiby(x-1, f1, f0 + f1)
end
end
fiby(n, 0, 1)
end
# test
N = Integer(ARGV.shift || 32)
require 'benchmark'
Benchmark.bm do |bm|
bm.report("original:") { puts fib(N) }
bm.report("ocaml way:") { puts fib2(N) }
end
Running this script gives the following output on my machine:
user system total real
original:3524578
8.531000 0.000000 8.531000 ( 8.531000)
ocaml way:3524578
0.000000 0.000000 0.000000 ( 0.000000)
The result of the computation is the same, but look at the runtime difference!
So please reject both the ocaml versions or let the other languages implement
the same algorithm.
Regards,
Pit
PS: I'm not subscribed to the mailing list.
More information about the Shootout-list
mailing list