You can use line_profiler
in jupyter notebook.
- Install it:
pip install line_profiler
- Within your jupyter notebook, call:
%load_ext line_profiler
- Define your function
prof_function
as in your example. - Finally, profile as follows:
%lprun -f prof_function prof_function()
Which will provide the output:
Timer unit: 1e-06 s
Total time: 3e-06 s
File: <ipython-input-22-41854af628da>
Function: prof_function at line 1
Line # Hits Time Per Hit % Time Line Contents
==============================================================
1 def prof_function():
2 1 1.0 1.0 33.3 x=10*20
3 1 1.0 1.0 33.3 y=10+x
4 1 1.0 1.0 33.3 return (y)