gpt4 book ai didi

Python 分析 : time spent on each line of function

转载 作者:太空狗 更新时间:2023-10-30 01:21:58 30 4
gpt4 key购买 nike

我一直在研究 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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com