gpt4 book ai didi

python - 我如何才能在 Python 或 IPython 中仅分析我的代码?

转载 作者:行者123 更新时间:2023-11-28 17:31:02 25 4
gpt4 key购买 nike

我熟悉 IPython 中使用 Python profile 模块的 %prun 魔术命令。但是,我只想分析我的代码。也就是说,我想看看我的 Python 代码中哪些行最慢,而不是我正在使用的某些外部包中深埋的那些行,它们经常被调用,因此看起来花费的时间最多。我该怎么做?

最佳答案

虽然 line_profiler 可以工作,但它会增加很多开销,您需要将 @profile 放在各处。

您可以用各种方式对 %prun 的输出进行排序。其中之一是模块名称:

%prun -s module my_func()

因此相应地选择您的文件名,例如以下划线开头,会将您的文件放在 %prun 显示的列表的开头。

关于python - 我如何才能在 Python 或 IPython 中仅分析我的代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34379003/

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