GetTickCount vs. clock for msec resolution

Mark Hammond MarkH at ActiveState.com
Fri Apr 20 01:36:23 EDT 2001


Les Schaffer wrote:

> i am talking to some hardware, needing to resolve 10's-100's of msec
> of time. So I started playing around with the clock and GetTickCount
> functions under win32 to check for finer time resolution.


  time.clock()is using the best resolution timer available.  It has a 
misleading name for hyster^h^h^h^h^historical reasons, but is mainly 
used by the profiler, so the best resolution the better.

  This also accounts for is providing "mis-leading" information on 
Win32.  First time you call it it returns a number very close to zero. 
Subsequentcalls are then relative to this first time.  This is fine for 
most apps tho as they only care about the difference, but does make the 
name "clock" seem a little strange!

Check out the win32 docs on QueryPerformanceCounter, which is used in 
the implementation.  (Or just check out the source-code :)

> i'm good and stickin with clock for now. But I am curious to hear
> other people's observations about msec time resolution or possibly
> even smaller, particularly on winXX and linux.


I believe that in general, if better timers for a platform become known 
they will be used in time.clock() so the profiler sees better 
resolution.  Therefore this is probably the safest function to use.

Mark.




More information about the Python-list mailing list