From: Martin Weber Date: 2003-08-26T01:59:26+09:00 Subject: Re: Rite/Ruby2.0 & Ruby vs OCaml On Tue, Aug 26, 2003 at 01:35:56AM +0900, Brian Candler wrote: > On Tue, Aug 26, 2003 at 12:40:45AM +0900, mark wrote: > (...) > I was actually just trying to get some timings out. It seems ocaml is > astoundingly fast for that test: 0.51s uncompiled, 0.37s compiled with > ocamlc, versus 11.6s for the Ruby equivalent: > > def sum(n) > total = 0 > n.times { |x| total += x } > total > end > > puts sum(1000000) > > OTOH, the Ruby version gives the right answer :-) a) the ocaml version gives the right answer, too if you b) use bignums. You're comparing apples to microsofts here, because ocaml is wrapping over native ints, while ruby automatically uses a Bignum when leaving Fixnum range. $ ocamlmktop -custom -o top nums.cma -cclib -lnums ./top (* sum.ml *) open Num;; let sum n = let one = (Int 1) in let rec aux v acc = if v