[python-win32] time. delay oddities
Ray S
rays at blue-cove.com
Tue Jan 25 23:28:24 CET 2005
With the pure Python code below, I get results like:
micro sec: 1.0 12.2 154.8
micro sec: 0.9 11.3 156.0
when requesting 0, 10 and 160 us, which seems reasonable - PII600 Win2K Py2.2.
On Linux with a 2GHz Py2.3 it seems to always return 0.0
Additionally, I don't see why mydelay works as it does; I have tried other
methods today, including an rdtsc DLL, and all other methodologies tried
are limited by overhead of the call to ctypes (for rdstc or waitabletimer)
or ~200ms clock granularity (averages, ignoring the randomness of MS timing).
Can someone explain it? Does it work the same on other machines?
Code snipped from:
http://edily.progiciels-bpi.ca/showfile.html?name=courriel/c%C3%A9duleur&index=1
CODE:
mytime = time.clock#time ## optimization
sleep = time.sleep
clock = time.clock
def mydelay(delay):
global logical_time
physical_time = mytime()
try:
logical_time = logical_time + delay
except NameError:
logical_time = physical_time + delay
if logical_time > physical_time:
## apparently only done when delays are > ~.001s
sleep(logical_time - physical_time)
#sleep(.001) ## same as above for small delays
#print (logical_time - physical_time) *1000. ## print ms
#sleep(.0001) ## same as sleep(0)!
p = 0.
d1 = 0.
d2 = 0.
looped = 0.
howMany = 100
for i in range(20):
## timer for pass in a for loop
t1 = clock()
for j in range(howMany):
pass
p += (clock()-t1)
t1 = clock()
mydelay(.000001)
for j in range(howMany):
mydelay(.00001) ## ~minumum useable ~10us
d1 += (clock()-t1)
t1 = clock()
for j in range(howMany):
mydelay(.00016)
d2 += (clock()-t1)
looped+= howMany
print 'micro sec: %.1f %.1f %.1f' % (1000000*p/looped,
1000000*d1/looped, 1000000*(d2)/looped)
More information about the Python-win32
mailing list