Last Updated: February 25, 2016
·
1.048K
· josericardo

Easily profiling python code line by line

$ pip install --pre line_profiler

Annotate the method(s) you want to profile (no need for imports):

@profile
def will_be_profiled():
  ... 

$ kernprof.py -l script.py

By now, a script.py.lprof file has been generated. To visualize the times of each line:

$ python -m line_profiler script.py.lprof