[racket] How can I measure time in nanoseconds?

From: Neil Toronto (neil.toronto at gmail.com)
Date: Fri Nov 12 17:58:44 EST 2010

Eli Barzilay wrote:
> 5 minutes ago, Jakub Piotr Cłapa wrote:
>> And in the case this is still not clear ;) the inexact part is not only 
>> about formal inexactnes but about limited timer resolution as well. 
>> Despite the CPU clock ticking more than once each nanosecond the 
>> procesor and OS does not really count the time this accurately. On 
>> normal OSes I would expect microsecond accuracy at best (but that is a 
>> guess; I didn't measure).
> 
> Easy to do, just run
> 
>   (- (current-inexact-milliseconds) (current-inexact-milliseconds))
> 
> a few times.
> 

Looping to collect 1000 differences, I consistently get a minimum of 
0.0009765625 milliseconds = 0.9765625 microseconds. Nice guess, Jakub.

I also get negative numbers, which is very weird.

Neil T



Posted on the users mailing list.