High resolution sleep (Linux)

John janzon at gmail.com
Fri May 4 06:22:02 EDT 2007


The table below shows the execution time for this code snippet as
measured by the unix command `time':

for i in range(1000):
	time.sleep(inter)

inter       execution time      ideal
0                     0.02 s            0 s
1e-4                4.29 s            0.1 s
1e-3                4.02 s            1 s
2e-3                4.02 s            2 s
5e-3                8.02 s            5 s

Hence it seems like the 4 s is just overhead and that the time.sleep
method treats values below approximately 0.001 as 0.

Is there a standard way (or slick trick) to get higher resolution? If
it is system dependent it's acceptable but not very nice :)




More information about the Python-list mailing list