August 2018
Intermediate to advanced
366 pages
10h 14m
English
For this recipe, the following steps are to be performed:
import time
def slowfunc(goslow=False):
l = []
for i in range(100):
l.append(i)
if goslow:
time.sleep(0.01)
return l
from cProfile import Profile profiler = Profile() profiler.runcall(slowfunc, True) profiler.print_stats()
202 function calls in 1.183 seconds Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno(function) 1 0.002 0.002 1.183 1.183 devtools_09.py:3(slowfunc) 100 1.181 0.012 1.181 ...