Python分析:在每行函数上花费的时间

ali*_*noi 5 python profile workflow numpy

我一直在研究配置文件中的示例,我在运行时已经进入了工作流程

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.
Run Code Online (Sandbox Code Playgroud)

这给了我一些关于调用次数等的一般统计数据.你要知道,这是相当神秘:我heaviliy使用numpy内部myFunc(如numpy.sum,*等),但我不能发现在统计的通话对象.我希望看到的是在函数源代码的每一行上花费的时间myFunc.我怎么做?

Gil*_*tes 3

PyPI 上有一个很好的包 -line_profiler