Re: Ruby - Computer Language Shootout [Fwd: Fibonacci Numbers: unfair entries for ocaml]
Pit Capitain <[email protected]> Tue, 19 Oct 2004 21:36:42 +0200
| Newsgroups | gmane.comp.lang.ruby.german |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format. --------------070908030908040602060903 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by rubyforge.org id i9JJadKd023181 Hallo, falls es euch interessiert, wie Ruby beim Berechnen der Fibonacci Zahlen = mit=20 Ocaml gleichziehen kann: ich habe gerade folgende E-Mail an die Mailing-L= iste=20 vom Computer Language Shootout geschickt. Gru=DF, Pit --------------070908030908040602060903 Content-Type: message/rfc822; name="Fibonacci Numbers: unfair entries for ocaml" Content-Disposition: inline; filename="Fibonacci Numbers: unfair entries for ocaml" Message-ID: <[email protected]> Date: Tue, 19 Oct 2004 21:28:48 +0200 From: Pit Capitain <[email protected]> User-Agent: Thunderbird 0.7 (Windows/20040616) X-Accept-Language: de-DE, de, en-us, en MIME-Version: 1.0 To: [email protected] Subject: Fibonacci Numbers: unfair entries for ocaml Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit 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. --------------070908030908040602060903 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Disposition: inline Content-Transfer-Encoding: 7bit _______________________________________________ Ruby-de-talk mailing list [email protected] http://rubyforge.org/mailman/listinfo/ruby-de-talk --------------070908030908040602060903--