How to measure elapsed time under Windows?

Paul McGuire ptmcg at austin.rr.com
Wed Feb 10 08:37:22 EST 2010


On Feb 10, 2:24 am, Dennis Lee Bieber <wlfr... at ix.netcom.com> wrote:
> On Tue, 9 Feb 2010 21:45:38 +0000 (UTC), Grant Edwards
> <inva... at invalid.invalid> declaimed the following in
> gmane.comp.python.general:
>
> > Doesn't work.  datetime.datetime.now has granularity of
> > 15-16ms.
>
> > Intervals much less that that often come back with a delta of
> > 0.  A delay of 20ms produces a delta of either 15-16ms or
> > 31-32ms
>
>         WinXP uses an ~15ms time quantum for task switching. Which defines
> the step rate of the wall clock output...
>
> http://www.eggheadcafe.com/software/aspnet/35546579/the-quantum-was-n...http://www.eggheadcafe.com/software/aspnet/32823760/how-do-you-set-ti...
>
> http://www.lochan.org/2005/keith-cl/useful/win32time.html
> --
>         Wulfraed         Dennis Lee Bieber               KD6MOG
>         wlfr... at ix.netcom.com     HTTP://wlfraed.home.netcom.com/

Gabriel Genellina reports that time.clock() uses Windows'
QueryPerformanceCounter() API, which has much higher resolution than
the task switcher's 15ms.  QueryPerformanceCounter's resolution is
hardware-dependent; using the Win API, and a little test program, I
get this value on my machine:
Frequency is 3579545 ticks/sec
Resolution is 0.279365114840015 microsecond/tick

-- Paul



More information about the Python-list mailing list