caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] OCaml speed
@ 2001-10-15 16:39 Rolf Wester
  2001-10-16 21:33 ` Markus Mottl
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Rolf Wester @ 2001-10-15 16:39 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 6+ messages in thread
* Re: [Caml-list] OCaml speed
@ 2001-10-17  4:11 Jeremy Fincher
  2001-10-17  8:01 ` Rolf Wester
  0 siblings, 1 reply; 6+ messages in thread
From: Jeremy Fincher @ 2001-10-17  4:11 UTC (permalink / raw)
  To: rolf.wester, caml-list

Try compiling with the -unsafe option.  The speed difference is most likely
largely due to the bounds-checking that .() does by default.

Jeremy

>ocamlopt -o aa_ml unix.cmxa aa.ml


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp

-------------------
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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2001-10-30 19:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-15 16:39 [Caml-list] OCaml speed Rolf Wester
2001-10-16 21:33 ` Markus Mottl
2001-10-16 21:43 ` Doug Bagley
2001-10-30 16:24 ` Christophe Raffalli
2001-10-17  4:11 Jeremy Fincher
2001-10-17  8:01 ` Rolf Wester

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).