Python Language Profiling line_profiler in command line


The source code with @profile directive before the function we want to profile:

import requests

def slow_func():
    s = requests.session()
    sum([pow(ord(x),3.1) for x in list(html)])
for i in range(50):

Using kernprof command to calculate profiling line by line

$ kernprof -lv

Wrote profile results to
Timer unit: 4.27654e-07 s

Total time: 22.6427 s
Function: slow_func at line 4

Line #      Hits         Time  Per Hit   % Time  Line Contents
     4                                           @profile
     5                                           def slow_func():
     6        50        20729    414.6      0.0      s = requests.session()
     7        50     47618627 952372.5     89.9      html=s.get("").text
     8        50      5306958 106139.2     10.0      sum([pow(ord(x),3.1) for x in list(html)])

Page request is almost always slower than any calculation based on the information on the page.