Version française
Home     About     Download     Resources     Contact us    
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
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

tmp123@menta.net 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.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGgRYIPp1Qsf2qnMcRAiC5AJkBPG/XrrH3mSZuP+YFTtLk+xF4YACdGmdF
zijSDKnxkm6BIpXDQ+DkLwE=
=lchS
-----END PGP SIGNATURE-----