calculating system clock resolution
Peter Hansen
peter at engcorp.com
Sat Apr 8 08:35:24 EDT 2006
Steven D'Aprano wrote:
> This brings me to an even simpler method of getting the resolution of
> time.time(), without the overhead of a while loop:
>
>>>>abs(time.time() - time.time())
>
> 1.0013580322265625e-05
> which is approximately 0.01ms, just as you expected.
This doesn't necessarily work, at least on Windows, where the
time.time() resolution is much worse than the time it takes to execute a
couple of calls to time.time(). Most of the time the values returned by
two consecutive time.time() calls are identical, differing only if the
timer just happens to tick between the two. (On my machine a simple
while loop that performs the above calculation until it produces a
non-zero value has to run on average over 10000 times.)
-Peter
More information about the Python-list
mailing list