This is an old revision of the document!
>>> import cProfile >>> cProfile.run('x = [i for i in range(10000000)]') 4 function calls in 0.719 seconds Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno(function) 1 0.568 0.568 0.568 0.568 <string>:1(<listcomp>) 1 0.151 0.151 0.719 0.719 <string>:1(<module>) 1 0.000 0.000 0.719 0.719 {built-in method exec} 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
def foo(iters): x = 0 for i in range(iters): x += 1 def bar(iters): x = 0 for i in range(iters): x += 1 def baz(iters): x = 0 for i in range(iters): x += 1 if __name__ == "__main__": foo(10000) bar(100000) baz(1000000)
$ python -m cProfile -s cumtime profile.py 8 function calls in 0.059 seconds Ordered by: cumulative time ncalls tottime percall cumtime percall filename:lineno(function) 1 0.000 0.000 0.059 0.059 profile.py:1(<module>) 1 0.035 0.035 0.054 0.054 profile.py:11(baz) 3 0.021 0.007 0.021 0.007 {range} 1 0.003 0.003 0.005 0.005 profile.py:6(bar) 1 0.000 0.000 0.000 0.000 profile.py:1(foo) 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}