[英]Python profiling: time spent on each line of function
我一直在研究配置文件中的示例,我在運行時已經進入了工作流程
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.
這給了我一些關於調用次數等的一般統計數據。 請注意,這是相當神秘的:我在myFunc
使用numpy
(比如numpy.sum
, *
等),但我無法在stats對象中找到這些調用。 我想看到的是在函數myFunc
的源代碼的每一行上花費的時間。 我怎么做?
在PyPI - line_profiler
上有一個很好的包
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.