[Tutor] Loop comparison

Alan Gauld alan.gauld at btinternet.com
Sat Apr 17 01:47:46 CEST 2010


>> > result = sum(range(1000000000))
>> >
>> > although it still took 10 minutes on my PC.
>>
>> Did you mean to say "minutes" or rather "seconds" here? And did you
>> really mean to use "range" or rather "xrange" (or "range" in Py3)?

Yes, minutes and in Python 3.
And on a 2.8GHz 2 core CPU with 2G RAM

>>      sum(xrange(1000000000))
>>
>> clearly runs in 12 seconds for me on Py2.6, 

Well over a minute on 2.5 under Cygwin.
Dropping by an order of magnitude took it down to 17 secs
Which is exactly the same in Python 3...

Alan G.




More information about the Tutor mailing list