wasm-demo/demo/ermis-f/python_m/cur/1812

44 lines
1.3 KiB
Plaintext

From: tim_one at email.msn.com (Tim Peters)
Date: Tue, 18 May 1999 00:46:10 -0400
Subject: while (a=b()) ...
In-Reply-To: <14144.26371.38718.411863@bitdiddle.cnri.reston.va.us>
Message-ID: <000801bea0e9$597de6c0$829e2299@tim>
Content-Length: 1048
X-UID: 1812
[Tim]
> You need to be much clearer about your claim here; certainly
> xrange(1000000) runs much faster than range(1000000) on anyone's
> machine (the former is constant time regardless of argument and
> the latter at best takes time proportional to a million), so
> your real complaint is about something else.
[Jeremy Hylton] [mailto:jeremy at cnri.reston.va.us]
> Actually, range(1000000) is faster on my machine. Something like 3%
> faster, but still faster. Of course, if the program can amortize the
> cost of creation/deletion across multiple iterations, it will be
> substantially faster.
from time import clock
N = 1000000
start1 = clock(); x = xrange(N); finish1 = clock()
start2 = clock(); y = range(N); finish2 = clock()
print "xrange time", finish1 - start1
print " range time", finish2 - start2
That prints
xrange time 0.000689753432005
range time 1.05385775826
for me, the third time I run it. The first time, range is 10000x slower
than xrange while Win95 swaps the world out to disk <wink>.
clearer?-ly y'rs - tim