Performance Issues please help

PyPK superprad at gmail.com
Wed Jun 1 19:34:08 EDT 2005


I was testing this piece of code and it takes about 24-30 seconds to do
a look up on a list(m) of size 1000x1000
m -> list of size 1000x1000
import time
print time.ctime()
box = {}
for r,row in enumerate(m):
    for c,e in enumerate(row):
         if box.has_key(e):
               params = box[e]
               box[e] = ( min(c, params[0]), min(r, params[1]),
                          max(c, params[2]), max(r, params[3] ) )
          else:
                box[e] = [c, r, c, r]
print time.ctime()

Can some one tell me what exactly is taking more time here. Is it
because I am using dictionaries or what is the problem. Can some one
help me improve this .Is there a better way to write this.




More information about the Python-list mailing list