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
Unix module troubles & Time functions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jean-Christophe Filliatre <filliatr@l...>
Subject: Re: [Caml-list] Unix module troubles & Time functions

Julien Michel writes:
 > I would like to measure the time a function spends inside a Caml
 > program, for performance purpose.
 > I need a function with an accuracy of at least 1us.
 > [...]
 > Or generally speaking, does any other function exists to achieve such a
 > measurement (accuracy about 1 us) ?

To do such a measurement, I'm using the Unix.times function, as

open Unix
let utime f x =                                                   
  let u = (times()).tms_utime in                                  
  let y = f x in
  let ut = (times()).tms_utime -. u in

let print_utime f x = 
  let (y,ut) = utime f x in
  Printf.printf "user time: %2.2f\n" ut;

Hope this helps,
Jean-Christophe Filliātre (