| Hosted by CoCalc | Download
Kernel: Python 3 (Ubuntu Linux)

Line Profiler in Python 3

def f(x, y): a = x + y b = 1 + a for i in range(100): c = a + b +x +y return c
%load_ext line_profiler
The line_profiler extension is already loaded. To reload it, use: %reload_ext line_profiler
%lprun -f f f(2, 3)
Timer unit: 1e-06 s Total time: 8.7e-05 s File: <ipython-input-4-a47eadbe5560> Function: f at line 1 Line # Hits Time Per Hit % Time Line Contents ============================================================== 1 def f(x, y): 2 1 2.0 2.0 2.3 a = x + y 3 1 0.0 0.0 0.0 b = 1 + a 4 101 39.0 0.4 44.8 for i in range(100): 5 100 45.0 0.5 51.7 c = a + b +x +y 6 1 1.0 1.0 1.1 return c