Optimizing Python code

 

 

http://code.activestate.com/recipes/578231-probably-the-fastest-memoization-decorator-in-the-/

The trick to writing high performance python code is to do the critical part with no python function calls in the inner loop. They are expensive.