I have been studying examples from the profile documentation and I have come to the workflow when I run
import cProfile as profile
import pstats
pr = profile.Profile()
pr.runcall(myFunc, args, kwargs)
st = pstats.Stats(pr)
st.print_stats() # and other methods like print_callees, print_callers, etc.
This gives me some general stats of the number of calls made and so on. Mind you, it is rather cryptic: I heaviliy use numpy
inside myFunc
(like numpy.sum
, *
and the like) but I cannot find those calls in the stats object. What I would like to see is the time spent on each line of the source code of function myFunc
. How do I do that?
There is a good package for that on PyPI - line_profiler
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