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?
在PyPI - line_profiler
上有一个很好的包
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.