How to measure elapsed time under Windows?

Grant Edwards invalid at invalid.invalid
Wed Feb 10 11:15:22 EST 2010


On 2010-02-09, Gabriel Genellina <gagsl-py2 at yahoo.com.ar> 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:
> http://support.microsoft.com/?id=896256

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?

>> Is there a way to lock the python process to a single core so
>> that time.clock() works right?
>
> Interactively, from the Task Manager:
> http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/taskman_assign_process.mspx

Thanks.  That looks a bit easier than disabling the second core
(which is what I ended up doing).

> In code, using SetProcessAffinityMask and related functions:
> http://msdn.microsoft.com/en-us/library/ms686223(VS.85).aspx

With help from google and some old mailing list posting I might
even try that.

-- 
Grant Edwards                   grante             Yow! It's a lot of fun
                                  at               being alive ... I wonder if
                               visi.com            my bed is made?!?



More information about the Python-list mailing list