In my experience, the easiest way to analyze Python performance is with the %time, %timeit and %prun magic commands in IPython, an alternative Python shell that is far more powerful than the original.
With IPython, you can simply write:
%time result = expensive_function()
and the time it takes to execute expensive_function() is printed out to the console. You can also directly substitute %timeit or %prun for %time to use loops for the timer or to invoke built-in profiler. No need to write any of your own boilerplate!
With IPython, you can simply write:
and the time it takes to execute expensive_function() is printed out to the console. You can also directly substitute %timeit or %prun for %time to use loops for the timer or to invoke built-in profiler. No need to write any of your own boilerplate!