Notes taken during a Performance talk given at PyConUK.

function calls

c method instead
cython instead

Use operators



list comprehension is quicker than for loop over an emnumerator

What is op?

xrange vs range
– no wasted memory

NB: In python3 renamed range


Or use a c extension



l.sort vs sorted() – any iterator

Key based:

look up operator -> operator.itemgetter

Can use on object attribute


“”.join([a, b, c]) faster but less readable

% method not that fast an ugly – don’t use

Int keys are faster than string keys

interned string keys – no garbage collection

sys.intern – P3

Variable look ups

Mentioned global variable trick

local var faster than global in general

Look up: Old style/new style classes??

Slot attributes ?? look up more just seemed to be attributes???

Don’t use exceptions as an often use case. => much faster say to use getattr than catch a valueexception

Try to rely on c methods

Profiling tools:
c profiler built into Python

cpython vs number – can make pythonrun as fast as C – suggestion