caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Rolf Wester" <rolf.wester@ilt.fhg.de>
To: caml-list@inria.fr
Subject: [Caml-list] OCaml speed
Date: Mon, 15 Oct 2001 18:39:01 +0200	[thread overview]
Message-ID: <3BCB2D45.29070.4316C73C@localhost> (raw)

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


             reply	other threads:[~2001-10-16 21:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-15 16:39 Rolf Wester [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3BCB2D45.29070.4316C73C@localhost \
    --to=rolf.wester@ilt.fhg.de \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).