如何在 Python 中检查代码的 运行 时间。 PyCharm 是我的 IDE

How to check run time of your code in Python. PyCharm is my IDE

如何检查我的代码执行需要多长时间。 python 中是否有内置方式?或者我的 IDE PyCharm 中是否有一些隐藏的工具让我这样做。

你可以试试

cProfile

这样:

import cProfile
def myFunc():
   ...

cProfile.run('myFunc()')

希望这能解决您的问题!

所以 profiler 已经是 Pycharm 中的内置工具,如果您没有安装 yappi,它默认使用 cProfiler。这里是 link 到 PyCharm profiler.

如果您想分析您的代码而不需要任何附件 PyCharm,请检查 SO 问题 How can you profile a Python script?