Speeding up a script -- looking for ideas
Erik Max Francis
max at alcyone.com
Sun Oct 20 10:38:59 CEST 2002
Richard Bow wrote:
> I'm hoping to get some hints for significantly speeding up the below
> script. I've found 43 integers between 1 and 1,000,000 that satisfy
> condition, and would like to push on toward 10,000,000 in hopes of
> an integer for which there are 3 pairs. Of course, another reason for
> asking is to learn more Python from you guys.
One obvious optimization is that you're using range with huge values,
which is going to be expensive -- range returns a list, so calling it
with large values will create an enormous list, which is wasteful if all
you plan on doing is enumerating it. Try using xrange, or iterating
Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/ \ The doors of Heaven and Hell are adjacent and identical.
\__/ Nikos Kazantzakis
Physics reference / http://www.alcyone.com/max/reference/physics/
A physics reference.
More information about the Python-list