English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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, romildo@uber.com.br 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 (Unix.select [] [] [] (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.