[Tutor] better resolution on time.sleep()?

jfouhy@paradise.net.nz jfouhy at paradise.net.nz
Tue May 24 00:59:57 CEST 2005


Quoting Roger Merchberger <zmerch at 30below.com>:

> I really only need between 500 and 1000 samples per second, but as the 
> smallest sleep available normally is time.sleep(.01) -- which brings my
> samples/sec to a nice 100; but I need it a little faster.

Where did you find that out?
 
> 2) will upgrading to a newer version of Python get me what I need?
> [[ I looked thru the "New in 2.4" dox and nothing I needed was
> listed...]]

I just did some experimenting ... I am running ActiveState Python 2.4.1 under
Windows XP / cygwin.

>>> def check():
...  now = time.clock()
...  for i in xrange(10000):
...   time.sleep(0.001)
...  print time.clock() - now
...
>>> check()
11.2695306247
>>> def check():
...  now = time.clock()
...  for i in xrange(100000):
...   time.sleep(0.0001)
...  print time.clock() - now
...
>>> check()
2.77601985727
>>> check()
8.70900742972

The first test is fairly consistent with time.sleep(0.001) doing what you
expect.  The second is a bit puzzling to me, though...

-- 
John.


More information about the Tutor mailing list