while (a=b()) ...
Tim Peters
tim_one at email.msn.com
Tue May 18 00:46:10 EDT 1999
[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
More information about the Python-list
mailing list