[Shootout-list] Re: OCaml harmonic benchmark
Jon Harrop
jon@ffconsultancy.com
Sun, 1 May 2005 18:27:54 +0100
On Sunday 01 May 2005 18:07, Isaac Gouy wrote:
> --- Jon Harrop <jon@ffconsultancy.com> wrote:
> > I've reformatted the OCaml harmonic benchmark, making it a few lines
> > shorter.
> > Surprisingly, this also made it twice as fast on my computer.
>
> This is a situation where it's interesting to show both programs.
Actually I was wrong. If you compile them with the same command that the
shootout uses then they have exactly the same running times. My new version
runs as fast without needing the "-inline 100" switch, although I'm not sure
why as I didn't think I'd inlined anything important...
Anyway, the time is hugely noisy because it is so short:
$ time ./harmonic.ocaml_run 10000000
16.695311366
real 0m0.184s
user 0m0.180s
sys 0m0.000s
$ time ./harmonic.ocaml_run 10000000
16.695311366
real 0m0.384s
user 0m0.200s
sys 0m0.010s
$ time ./harmonic.ocaml_run 10000000
16.695311366
real 0m0.259s
user 0m0.200s
sys 0m0.000s
For n = 10^8 instead, the times are insignificantly different for the old and
new versions.
Incidentally, I was going to submit this:
let sum = ref 1.0 and ifloat = ref 2.0;;
for i = 2 to int_of_string Sys.argv.(1) do
sum := !sum +. 1.0 /. !ifloat;
ifloat := !ifloat +. 1.0
done;;
Printf.printf "%0.9f\n" !sum
but it is vastly slower, probably because ocamlopt fails to unbox the floats.
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists