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
Simple clock
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-12-14 (21:53)
From: Ville-Pertti Keinonen <will@e...>
Subject: Re: [Caml-list] Simple clock
On Tue, 2004-12-14 at 18:39 -0200, wrote:

> Particularly, the while, print_tm and print_newline execution
> time is not counted. Would that introduce an accurace in
> my clock? If so, is that inevitable?

It'll always print the correct time, at approximately one-second
intervals, but as you suspect, it'll drift over time.

What you probably want for the delay is something like:

ignore ( [] [] [] (1.0 -. (fst (modf (Unix.gettimeofday

Unix.gettimeofday () returns the time as a floating point number with
reasonable accuracy, modf splits it into fractional and integral parts,
fst selects the first one (the fractional part), so the select returns
at (or as close to as possible) the next integral second.