for loops longer on a P-IV???

Chris Christopher.Cox at
Thu Aug 1 03:23:51 CEST 2002

I previously posted an oddity with what I thought to be a problem with
the win32api.Sleep() function on a P-IV system.  After some more
investigation, it looks like the for loop we use in our function is
causing a significantly larger amount of time to execute on out P-IV
system than on our P-III system.  This is our wait function:
def wait(Seconds):
	loop = Seconds * 50
	for i in range (0,loop):
		if win32ui.PumpWaitingMessages(0,-1):
			raise exceptions.SystemExit

A 10 second wait on our P-IV seems to take 15 seconds as shown by the
following miniscule test:
import time
import win32api
def test(sec):
    print time.clock()
    print time.clock()

The results were consistently 50% longer than expected.  I removed the
if clause and it's statements and found the same result.  I then
rewrote the wait function as follows:
def wait(second):
    win32api.Sleep(1000 * second)

Running the test again with the updated version of the wait function,
I got expected results of 10 second waits.  I haven't tried using a
while loop instead of the for loop yet, so I'm not sure if this
applies to all loops or just the for construct.  Am I missing
something blatantly obvious, or is there some known issue with the way
the P-IV optimizes code at runtime?

More information about the Python-list mailing list