Using gettimeofday , like the accepted answer, is not a good idea, since it is sensitive to the settings of the calendar time operating system (for example, via ntp ).
If you just need CPU time, then using Sys.time great. If you want a wall clock, you should use a monotonous time source. One of them is available for OCaml in the mtime package.
source share