[
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: | -- (:) |
| From: | Rolf Wester <rolf.wester@i...> |
| Subject: | [Caml-list] OCaml speed |
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</a> by Brian W. Kernighan and
* Christopher J. Van Wyk.
*
* I added free() to deallocate memory.
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
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