Laughing at myself

Alex Martelli aleax at aleax.it
Tue May 13 04:25:19 EDT 2003


Daniel Fackrell wrote:

> "Alex Martelli" <aleax at aleax.it> wrote in message
> news:DPPva.83326$3M4.1952662 at news1.tin.it...
>> Daniel Fackrell wrote:
>>    ...
>> > time.sleep(0.000001)
>> >
>> > works just fine, and apparently perfectly.
>> >
>> > Thanks to Alex Martelli for being the one who set me a bit closer to
>> > the true path.
>>
>> You're welcome!  Though I'm not sure how exactly I did that -- perhaps
>> the sentence in the Nutshell, p. 247, 'secs is a floating-point number
>> and can indicate a fraction of a second', did serve its intended purpose?
> 
> Actually, it was your post on the thread titled, "getting system date"
> which was started by Psybar Phreak, and the attached thread "Just good
> advice?". While I would love to have Nutshell, I haven't been able to get
> it yet.

Thanks!  It does help to know what fraction of my abundant writing does end
up being useful to somebody.

However, take care about the "apparently perfectly" bit.  E.g.:


import time

liston = [None] * 1000 * 1000

start = time.time()
for x in liston: pass
stend = time.time()

without_sleep = stend-start

start = time.time()
for x in liston: time.sleep(0.000001)
stend = time.time()

with_sleep = stend-start

print without_sleep, with_sleep


On this Linux box I observe:

[alex at lancelot psyco-1.0]$ python ap.py
0.25779902935 2.6211950779
[alex at lancelot psyco-1.0]$ python ap.py
0.237923979759 2.11019694805
[alex at lancelot psyco-1.0]$ python ap.py
0.232311964035 2.13127195835
[alex at lancelot psyco-1.0]$ python ap.py
0.233944058418 2.07932901382
[alex at lancelot psyco-1.0]$

i.e., the difference between the loops with and without a million
microsecond sleeps is NOT about one second's elapsed time -- it
varies by run, but it tends to be closer to TWO seconds here.
YMMV...


Alex





More information about the Python-list mailing list