[python-win32] sleep() for less than .001s?

Tim Roberts timr at probo.com
Fri Aug 4 20:01:07 CEST 2006


Ray Schumacher wrote:

>In the attached test code, I get - for test in  [0, .1, .01, .001, .00001] seconds 
>
>    # 2.9us hi 5.2us low, 
>    # 110ms hi and low, 
>    # 16ms hi and low, 
>    # 16ms hi and low, 
>    # 2.9us hi 5.2us low
>
>Intestingly, if I un-comment the 
>    #print '\r',
>then the processor usage drops by ~11 per cent.
>
>If anyone has comments on these sleep() results, please enlighten me as to why.
>  
>

What surprises you?  The Win32 Sleep() function takes integer
milliseconds.  Thus, .00001 will round to 0, which says "give up the CPU
only if a higher-priority task is waiting.".

The default scheduling interval on your system is 16ms.  Some Windows
systems use that, some use 10ms; it depends on the HAL.  Windows only
checks for timer expiration when its scheduling runs, and the scheduler
doesn't run any more often than that.  You can reduce that to 1ms by
using timeBeginPeriod (I said timeBeginTime before; that was wrong), but
it will cost overall system performance, because you're getting
interrupts 16x as often.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the Python-win32 mailing list