Re:Ask HN: Help finding python profiling article
by mrfusion on Friday June 13, 2014 @08:26AM
(#7888425)
I usually turn garbage collection off, and then explicitly call it just in places where I need to free up memory. I get a modest 5-10% speed boost from that alone.
Another trick is to look at your innermost loops, and make sure you aren't doing accessing anything fancier than a variable.
Example
Bad:
for i in onemillionthings:
for j in onemillionotherthings:
print SomeClass.otherthing.A
Better:
tempvar=SomeClass.otherthing.A
for i in onemillionthings:
for j in onemillionotherthings:
print tempvar
Another trick is to look at your innermost loops, and make sure you aren't doing accessing anything fancier than a variable.
Example
Bad:
for i in onemillionthings: for j in onemillionotherthings: print SomeClass.otherthing.A
Better: tempvar=SomeClass.otherthing.A for i in onemillionthings: for j in onemillionotherthings: print tempvar