When I display profiling data using pstats
, the first column is the number of calls for each function.
However, when I sort data, I have choice between calls
, ncalls
and pcalls
keys. Documentation says that calls
and ncalls
are call count, when pcalls
is primitive call count. Is sorting by calls
or ncalls
is the same? What is different with pcalls
?
We define primitive to mean that the call was not induced via recursion. ...when the function does not recurse, these two values are the same. Sorting by calls or ncalls is the same.
cProfile: A deterministic profiler It works by tracing every function call in a program. That's why it's a deterministic profiler: if you run it with the same inputs it'll give the same output. By default cProfile measures wallclock time—how much time elapsed during the function run.
http://docs.python.org/2/library/profile.html#module-cProfile
We define primitive to mean that the call was not induced via recursion.
...when the function does not recurse, these two values are the same
Sorting by calls
or ncalls
is the same.
When there are two numbers in the first column (for example, 43/3), then the latter is the number of primitive calls, and the former is the actual number of calls. Note that when the function does not recurse, these two values are the same, and only the single figure is printed:
In [43]: def a(i):
....: if i == 0:
....: return
....: a(i-1)
....:
In [54]: %prun a(0)
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.000 0.000 <ipython-input-43-25b7f3d268b8>:1(a)
In [55]: %prun a(1)
ncalls tottime percall cumtime percall filename:lineno(function)
2/1 0.000 0.000 0.000 0.000 <ipython-input-43-25b7f3d268b8>:1(a)
In [56]: %prun a(3)
ncalls tottime percall cumtime percall filename:lineno(function)
4/1 0.000 0.000 0.000 0.000 <ipython-input-43-25b7f3d268b8>:1(a)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With