Browse thread
Ocaml sums the harmonic series -- four ways, four benchmarks: floating point performance
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2005-01-23 (02:59) |
From: | Oliver Bandel <oliver@f...> |
Subject: | Re: [Caml-list] Ocaml sums the harmonic series -- four ways, four benchmarks: floating point performance |
On Thu, Jan 13, 2005 at 10:53:16AM -0500, Will M. Farr wrote: [...] > Here's the code for the fastest implementation: > > let sum_harmonic4 n = > let sum = ref 1.0 in > let ifloat = ref 2.0 in > for i = 2 to n do > sum := !sum +. 1.0/.(!ifloat); > ifloat := !ifloat +. 1.0 > done; > !sum;; > > let _ = > let n = int_of_string (Sys.argv.(1)) in > Printf.printf "%g\n" (sum_harmonic4 n);; I tried harmonic4 on Powerbook G4, 400 MHz and the native-code needs about 1 min 50s. The Bytecode for harmonic4 runs in about 1min 53 s. It seems that there is no real distinction between bytecode and native code. At least on that system, #or at least on that task. I use Panther OS. It seems that it's more than twice as fast as your OS (look at the processor frequency: 400 MHz on my PB G4, 800 MHz on yours...). Which OS are you running? An older version of Mac-OS-X? Or Linux? (which one?) Maybe you can speed-up your calculations a lot, when installing a different operating system on your computer. I didn't try the other implementations. IMHO you can gain more performance easier, when changing your OS. Easier than looking at some code optimizations...?! (which you nevertheless can do too) Ciao, Oliver