From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 80A4DBB91 for ; Sun, 23 Jan 2005 03:59:05 +0100 (CET) Received: from first.in-berlin.de (dialin-145-254-054-020.arcor-ip.net [145.254.54.20]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j0N2x4Ph016148 for ; Sun, 23 Jan 2005 03:59:04 +0100 Received: by first.in-berlin.de (Postfix, from userid 501) id 00B10A2044; Sun, 23 Jan 2005 03:27:13 +0100 (CET) Date: Sun, 23 Jan 2005 03:27:13 +0100 From: Oliver Bandel To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Ocaml sums the harmonic series -- four ways, four benchmarks: floating point performance Message-ID: <20050123022713.GA4333@first.in-berlin.de> References: <3D3A6BF5-657B-11D9-A551-000393A34E82@mit.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3D3A6BF5-657B-11D9-A551-000393A34E82@mit.edu> User-Agent: Mutt/1.5.6i X-Miltered: at nez-perce with ID 41F312F8.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; oliver:01 bandel:01 oliver:01 in-berlin:01 caml-list:01 ocaml:01 wrote:01 argv:01 printf:01 printf:01 native-code:01 bytecode:01 bytecode:01 imho:01 ...:98 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.0 X-Spam-Level: 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