From: jeremy at cnri.reston.va.us (Jeremy Hylton)
Date: Tue, 18 May 1999 10:56:25 -0400 (EDT)
Subject: while (a=b()) ... (transmogrified to a range thread)
In-Reply-To: <000801bea0e9$597de6c0$829e2299@tim>
References: <14144.26371.38718.411863@bitdiddle.cnri.reston.va.us>
	<000801bea0e9$597de6c0$829e2299@tim>
Message-ID: <14145.32200.922535.384322@bitdiddle.cnri.reston.va.us>
Content-Length: 1281
X-UID: 1759                                                

>>>>> "TP" == Tim Peters <tim_one at email.msn.com> writes:

  TP> [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.

  TP> [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.

TP> from time import clock
TP> N = 1000000
TP> start1 = clock(); x = xrange(N); finish1 = clock()
TP> start2 = clock(); y =  range(N); finish2 = clock()
TP> print "xrange time", finish1 - start1
TP> print " range time", finish2 - start2

Right.  I was timing an iteration over the range -- 
    for i in xrange(N): pass
vs.
    for i in range(N): pass
In this case, range nearly always wins -- even for N == 1000000.

I see now that your point was a bit different than I took it to be.
So the original comment about range was really a complaint about
something else.  

Jeremy




