From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id XAA00052; Tue, 16 Oct 2001 23:08:54 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id XAA32738 for caml-list@pauillac.inria.fr; Tue, 16 Oct 2001 23:08:53 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA11192 for ; Mon, 15 Oct 2001 18:39:10 +0200 (MET DST) Received: from mailgw1.fhg.de (mailgw1.fhg.de [153.96.1.2]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f9FGd9v21166 for ; Mon, 15 Oct 2001 18:39:09 +0200 (MET DST) Received: from ilt.fhg.de (ilt.ilt.fhg.de [153.96.180.2]) by mailgw1.fhg.de (8.11.1/8.11.1) with ESMTP id f9FGd5e08497 for ; Mon, 15 Oct 2001 18:39:05 +0200 (MET DST) Received: from eent359 (iltpc123.ilt.fhg.de [192.102.148.123]) by ilt.fhg.de (8.9.3/8.9.3) with ESMTP id SAA23647 for ; Mon, 15 Oct 2001 18:39:08 +0200 (MET DST) From: "Rolf Wester" To: caml-list@inria.fr Date: Mon, 15 Oct 2001 18:39:01 +0200 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: [Caml-list] OCaml speed Message-ID: <3BCB2D45.29070.4316C73C@localhost> X-mailer: Pegasus Mail for Win32 (v3.12cDE) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi, I used the array access example from http://www.bagley.org/~doug/shootout/ to compare c/c++ speed against ocaml. The sources I used are attached below. Unfortunately I could not confirm the given cpu times which are 0.11 sec for gcc and 0.13 for ocamlopt. My results on a Compaq Alpha True64 are 0.05 for cxx, 0.1 for g++ and 0.29 for ocamlopt. Does anybody have an idea what could be the reason for this inconsistency? Did I do anything wrong? Rolf Wester ocaml ---------- (* * $Id: ary3.ocaml,v 1.2 2001/07/28 21:52:55 doug Exp $ * http://www.bagley.org/~doug/shootout/ * with help from Markus Mottl *) let run n = let time0 = Unix.times() in let lix = n - 1 and x = Array.make n 0 and y = Array.make n 0 in for i = 0 to lix do x.(i) <- i + 1 done; for k = 0 to 999 do for i = lix downto 0 do y.(i) <- x.(i) + y.(i) done done; Printf.printf "%d %d\n" y.(0) y.(lix); let time1 = Unix.times() in Printf.printf "Zeit = %f\n" (time1.Unix.tms_utime -. time0.Unix.tms_utime);; run 10000;; ocamlopt -o aa_ml unix.cmxa aa.ml +++++++++++++++++++++++++++++++++++++++++++++++++++++++ cpp ---- /* -*- mode: c -*- * $Id: ary3.gcc,v 1.1 2001/05/31 02:27:48 doug Exp $ * http://www.bagley.org/~doug/shootout/ * * this program is modified from: * http://cm.bell-labs.com/cm/cs/who/bwk/interps/pap.html * Timing Trials, or, the Trials of Timing: Experiments with Scripting * and User-Interface Languages by Brian W. Kernighan and * Christopher J. Van Wyk. * * I added free() to deallocate memory. */ #include #include #include clock_t cpu_time0; clock_t cpu_time1; int main(int argc, char *argv[]) { cpu_time0 = clock(); int n = 10000; int i, k, *x, *y; x = (int *) calloc(n, sizeof(int)); y = (int *) calloc(n, sizeof(int)); for (i = 0; i < n; i++) { x[i] = i + 1; } for (k=0; k<1000; k++) { for (i = n-1; i >= 0; i--) { y[i] += x[i]; } } fprintf(stdout, "%d %d\n", y[0], y[n-1]); free(x); free(y); cpu_time1 = clock(); fprintf(stdout, "%f \n", float(cpu_time1 - cpu_time0) / float(CLOCKS_PER_SEC)); return(0); } g++/cxx -O3 -o a_cpp aa.cpp ------------------------------------- Rolf Wester wester@ilt.fhg.de ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr