大约 8-9 年前,我看到了一个用于 Visual Studio 的工具(我不太记得名字了),它可以可视化函数调用及其性能。我真的很喜欢它,所以我想知道在 Python 中是否有类似的东西。假设您具有三个函数:
def first_func():
...
def second_func():
...
for i in xrange(10):
first_function()
...
def third_func():
...
for i in xrange(5):
second_function()
...
所以,该工具的最终报告是这样的(包括连接图):
first_func[avg 2ms] <--50 times--< second_func[avg 25ms] <--5 times--< third_func[avg 140ms]
像这样的工具可以更容易地找到系统中的瓶颈。特别是对于大型系统。
请您参考如下方法:
您可以使用与 python 安装捆绑在一起的探查器。 Python Profiler Link
