News for hackers. Stuff that matters.
Re:A Python Optimization Anecdote by mace on Wednesday October 26, 2011 @04:34AM (#3157648)
This is slightly better, IMHO: http://www.python.org/doc/essays/list2str.html

Some best practices when optimizing CPython code:

* Re-evaluate your algorithm (an inefficient quicksort is still faster than an optimized bubblesort)

* Use Python functions and constructs implemented in C (ex. most builtins, list comprehensions)

* Move loops from outside functions to inside (function call overhead is high)

* Use try/except to handle uncommon cases rather than using conditional checks in a loop.

* Eliminate dots (attribute lookup) in tight loops (create a local alias if needed)

See also: http://wiki.python.org/moin/PythonSpeed/PerformanceTips

There are no comments on this comment yet.