Making code faster
Sean 'Shaleh' Perry
shalehperry at attbi.com
Tue Jul 16 13:17:06 EDT 2002
>>>
>>> i = -1
>>> print 'loading file'
>>> def tmp1(s):
>>> global i
>>> i += 1
>>> return QSimpleViewItem(i,self.sv.lv.newColor,eval(s))
>>>
you use a global --> time hit
>>> tmp = myfile.readlines()
readlines is highly optimized
>>> print 'lines loaded'
>>> datei.close()
>>> self.sv.lv.rows = map(tmp1,tmp)
>>> self.sv.lv.visible = range(len(self.sv.lv.rows))
>>> print 'lines decoded',self.sv.lv.rows[0].col[0]
>>>
>>> Any ideas? It is astonishing that loading the lines from
>>> external storage takes much less time than the mapping
>>> itself!
>>
Have you actually used a profiler on the code to see where the time was going?
Could your call to eval() not be where the time is going?
More information about the Python-list
mailing list