About Python execution speed

Leonardo Giordani leonardo.giordani at treuropa.com
Mon Apr 12 05:51:02 EDT 2010


Hi all,

I'm facing a strange issue in Python execution speed. I'm running the
following test script:

---------------------------------8<-----------------------------------------

dim = 1000
iteration = 100000

list1 = []
list2 =  []

for i in range(dim):
    list1.append(float(i))
    list2.append(float(i) * 0.264)

for k in range(iteration):
    for j in range(dim):
        ris = 0
        ris = ris + list1[j] + list2[j]

---------------------------------8<-----------------------------------------

which runs in about 80 seconds on my local hardware (mean of multiple
execution)
If I move the whole code into a function and call this latter the execution
time drops to about 45 seconds.

What is the reason of this improvement?

Thank you very much in advance.

Leonardo Giordani
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100412/8ad88a7d/attachment.html>


More information about the Python-list mailing list