jemnotesversion 2 / featuring this entry or see all/search

May 22
cProfile and friends work well for profiling larger programs where things are split into functions. For more detailed investigation, however, you need something like line_profiler, where you can see output like this (trimmed):
Line #      Hits         Time  Per Hit   + Time  Line Contents
==============================================================
...
202      1741        12946      7.4      0.0      for k in zip(K.I, K.J):
203      1740       222659    128.0      0.9          K[k] = randn()
...
Once installed, decorate any function worthy of analysis with @profile, run kernprof.py -l <scriptname.py> and then view results with python -m line_profiler <scriptname>.lprof. Works well.