Handy Python Profiler: line_profiler + kernprof

Yao Yao on August 4, 2017

Just take a look at an exemplar output and you’ll know what they are designed for.


# Decorate your function of interest in your python script, say "foo.py". 
# No import is needed.
# Just ignore the error of `unresolved reference 'profile'`
# Make sure the decorated function is called.

def Proc2():

if __name__ == '__main__':
kernprof -l foo.py
python -m line_profiler foo.py.lprof

    # ----- OR SIMPLY----- #

kernprof -l -v foo.py

blog comments powered by Disqus