time.clock() and precision...

Tim Peters tim_one at email.msn.com
Sat Aug 12 03:47:56 EDT 2000


[Lurker]
> I am writing some code that does some timing. I am writing it for
> both a MS-Windows machine and a GNU/Linux box (RH 6.2).
>
> Problem: the precision of the time.clock() function is fine on
> MS-Windows, but not on GNU/Linux where it is only precises to
> 0.01 seconds.
>
> I am working in milliseconds. Is there a way to get the precision I
> need???

Windows-specific code in Python's implementation of time.clock() accesses
the very high precision MS QueryPerformanceCounter API (well, that's
specific to Win32 systems for now).  Under other systems, you get whatever
clock() function (if any) is defined by the platform C library; on Unix
derivatives, clock() generally isn't good to better than 0.01 second, and
note that it measures "CPU time", not wall-clock time.  time.time() may or
may not work better for you, but measures wall-clock time on all systems.
If it doesn't work better for you, you're out of luck (and would probably
also be out of luck if you were coding in C).

windows-ain't-all-bad<wink>-ly y'rs  - tim






More information about the Python-list mailing list