Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Execution time of class versus record
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Sam Steingold <sds@g...>
Subject: Re: Execution time of class versus record
Hash: SHA1 wrote:
> Hello,
> I've tried to implement two equivalent small programs, the one using
> class, the other one using records. The resulting execution times says
> that class are 7-8 times slower than record (compiled with ocamlopt in a
> Intel machine).

As other have explained, classes use hash table lookup per slot access,
while records access fields by offsets computed at compile-time.

> Please, knows someone what I'm doing wrong?
>  let t0 = Unix.gettimeofday () in
>  Printf.printf "elapsed = %f\n" (Unix.gettimeofday() -. t0)

Unix.gettimeofday is "wall clock".
Unix.times is "CPU time".
use the latter to time your programs because the former depends on the
machine load at the time of the test while the latter does not.

Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla -