Overflow exceptions are slow!

Aahz aahz at pythoncraft.com
Sun Dec 8 14:10:22 EST 2002


In Python 2.2, compare the following two loops for speed:

print "Starting loop 1"
start = time.clock()
L1 = []
for i in loop:
    L1.append(1L * i * i)
end = time.clock()
print "Loop 1 took", end - start, "seconds"

print "Starting loop 2"
start = time.clock()
L2 = []
for i in loop:
    L2.append(i * i)
end = time.clock()
print "Loop 2 took", end - start, "seconds"
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"To me vi is Zen.  To use vi is to practice zen.  Every command is a
koan.  Profound to the user, unintelligible to the uninitiated.  You
discover truth everytime you use it."  --reddy at lion.austin.ibm.com



More information about the Python-list mailing list