Python 分析 : time spent on each line of function

标签 python numpy workflow profile

我一直在研究 profile documentation 中的示例并且我运行的时候已经到了工作流程

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* 和之类的),但我无法在统计对象中找到这些调用。我想看到的是在函数myFunc 的源代码的每一行上花费的时间。我该怎么做?

最佳答案

在 PyPI 上有一个很好的包 - line_profiler

关于Python 分析 : time spent on each line of function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27525375/

相关文章:

python - 在 Mac OS 上使用 easy_install 安装 pip

python - 在 Cython 中使用 zlib 压缩 NumPy 数组

python - 编写一个程序,查找数字列表中最大的元素并与最后一个元素切换索引位置

python - 将按键修饰符与搅拌器模式一起使用

python - 您传递给模型的 Numpy 数组列表不是模型预期的大小。预计会看到 2 个数组

workflow - 用于自定义 TFS Build 2010 的资源

python - 将可选的输入文件全部放入 Snakemake 中

javascript - 如何更改 Alfresco ftl (freemarker) 控件的基域?

python - Windows 上的 os.stat()

python - Numpy 托普利茨矩阵