time.clock() or Windows bug?

Theo v. Werkhoven theo at van-werkhoven.nl.invalid
Sun Jun 8 22:57:00 CEST 2008


The carbonbased lifeform Nick Craig-Wood inspired comp.lang.python with:
> Theo v. Werkhoven <theo at van-werkhoven.nl.invalid> wrote:
>>  Output:
>>  Sample 1, at 0.0 seconds from start; Output power is: 8.967 dBm
> [snip]
>>  Sample 17, at 105.7 seconds from start; Output power is: 9.147 dBm
>>  Sample 18, at 112.4 seconds from start; Output power is: 9.284 dBm
>>  Sample 19, at 119.0 seconds from start; Output power is: 9.013 dBm
>>  Sample 20, at 125.6 seconds from start; Output power is: 8.952 dBm
>>  Sample 21, at 91852.8 seconds from start; Output power is: 9.102 dBm
>>  Sample 22, at 91862.7 seconds from start; Output power is: 9.289 dBm
>>  Sample 23, at 145.4 seconds from start; Output power is: 9.245 dBm
>>  Sample 24, at 152.0 seconds from start; Output power is: 8.936 dBm
> [snip]
>>  But look at the timestamps of samples 21, 22 and 43.
>>  What is causing this?
>>  I've replaced the time.clock() with time.time(), and that seems to
>>  solve the problem, but I would like to know if it's something I
>>  misunderstand or if it's a problem with the platform (Windows Server
>>  2003) or the time.clock() function.
>
> time.clock() uses QueryPerformanceCounter under windows.  There are
> some known problems with that (eg with Dual core AMD processors).
>
> See http://msdn.microsoft.com/en-us/library/ms644904.aspx
>
> And in particular
>
>     On a multiprocessor computer, it should not matter which processor
>     is called. However, you can get different results on different
>     processors due to bugs in the basic input/output system (BIOS) or
>     the hardware abstraction layer (HAL). To specify processor
>     affinity for a thread, use the SetThreadAffinityMask function.

Alright, that explains that then.

> I would have said time.time is what you want to use anyway though
> because under unix time.clock() returns the elapsed CPU time which is
> not what you want at all!

You're right, using fuctions that do not work cross platform isn't
smart.
Cheers for the explanation Nick

Theo
-- 
theo at van-werkhoven.nl    ICQ:277217131                      SuSE Linux
linuxcounter.org: 99872  Jabber:muadib at jabber.xs4all.nl  AMD XP3000+ 1024MB
"ik _heb_ niets tegen Microsoft, ik heb iets tegen
 de uitwassen *van* Microsoft"



More information about the Python-list mailing list