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
Re: [Caml-list] time complexity on basic data types
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Xavier Leroy <Xavier.Leroy@i...>
Subject: Re: [Caml-list] time complexity on basic data types
> > What facilities exist for timing constructs in Caml? I see 
> >            val times : unit -> process_times
> > in the manual, under unix system calls.

The most portable way to time a piece of code is via the Sys.time()
function.  It's part of the OCaml standard library, so it's guaranteed
to work on all ports of OCaml -- even non-Unix ones.

The Unix.times() function is more Unix-specific and is provided by an
external library, which you have to request explicitly (as Neel

> Second,
> for reasons I don't understand the Unix library is not linked by 
> default,

The main reason is that it might not be available (on a non-Unix
platform, for instance).  (OK, both the Windows and the MacOS ports of
OCaml have reasonable Unix emulation built-in, but that wasn't always
the case, and hypothetical ports to other OSes might not have it either.)
In other terms, the modules that are linked by default, that is, those
in the standard library, are the modules that are available
everywhere; other modules are in separate libraries, not linked in by

> In addition to this, you can also use the nice profiler that comes
> with the OCaml distribution, which gives you all sorts of fancy 
> instruction counts. That's in chapter 16 of the Caml manual:
> <URI:>

Correct.  There's also the option of using ocamlopt -p in conjunction
with the Unix profiler "gprof".

- Xavier Leroy
Bug reports:  FAQ:
To unsubscribe, mail  Archives: