How to measure elapsed time under Windows?

Gabriel Genellina gagsl-py2 at
Wed Feb 10 23:37:36 CET 2010

En Wed, 10 Feb 2010 13:15:22 -0300, Grant Edwards  
<invalid at invalid.invalid> escribió:
> On 2010-02-09, Gabriel Genellina <gagsl-py2 at> wrote:
>> En Tue, 09 Feb 2010 13:10:56 -0300, Grant Edwards
>> <invalid at invalid.invalid> escribi?:
>>> What's the correct way to measure small periods of elapsed
>>> time.  I've always used time.clock() in the past:
>>> However on multi-processor machines that doesn't work.
>>> Sometimes I get negative values for delta.  According to
>>> google, this is due to a bug in Windows that causes the value
>>> of time.clock() to be different depending on which core in a
>>> multi-core CPU you happen to be on.   [insert appropriate
>>> MS-bashing here]
>> I'm not sure you can blame MS of this issue; anyway, this
>> patch should fix the problem:
> I'm curious why it wouldn't be Microsoft's fault, because
>  A) Everything is Microsoft's fault. ;)
>  B) If a patch to MS Windows fixes the problem, how is it not a
>     problem in MS Windows?

I won't argue against A) because its truthness (?) is self-evident :)

99% of my code does not run in Python 3.x; I may fix it and it will  
eventually run fine, but that doesn't mean it's *my* fault.

The original problem was with the RDTSC instruction on multicore CPUs;  
different cores may yield different results because they're not  
synchronized at all times.

Windows XP was launched in 2001, and the first dual core processors able  
to execute Windows were AMD Opteron and IBM Pentium D, both launched  
around April 2005 (and targeting the server market, not the home/desktop  
market of Windows XP).
How could MS know in 2001 of a hardware issue that would happen four years  
in the future?
Guido seems very jealous of his time machine and does not lend it to  

Gabriel Genellina

More information about the Python-list mailing list