如何读取 IPython %prun(分析器)命令的输出?
我运行这个:
In [303]: %prun my_function()
384707 function calls (378009 primitive calls) in 83.116 CPU seconds
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function)
37706 41.693 0.001 41.693 0.001 {max}
20039 36.000 0.002 36.000 0.002 {min}
18835 1.848 0.000 2.208 0.000 helper.py:119(fftfreq)
--snip--
tottime、percall、cumtime 分别做什么? ncalls 相当明显(调用函数的次数)。我的猜测是,tottime 是在函数中花费的总时间,不包括在其自己的函数调用中花费的时间; percall 是 ???; cumtime 是函数调用所花费的总时间,包括其自身函数调用所花费的时间(当然,不包括重复计算)。 文档不是太有帮助了;谷歌搜索也没有帮助。
I run this:
In [303]: %prun my_function()
384707 function calls (378009 primitive calls) in 83.116 CPU seconds
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function)
37706 41.693 0.001 41.693 0.001 {max}
20039 36.000 0.002 36.000 0.002 {min}
18835 1.848 0.000 2.208 0.000 helper.py:119(fftfreq)
--snip--
What do each of tottime, percall, cumtime? ncalls is fairly obviously (number of times the function is called). My guess is that tottime is the total time spent in the function excluding time spent within its own function calls; percall is ???; cumtime is total time spent in the function call including time spent within its own function calls (but of course, excluding double counting). The docs are not too helpful; Google search doesn't help either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它只是 Python 自己的分析器的一个方便的包装器,其文档位于:
http: //docs.python.org/library/profile.html#module-pstats
引用:
It's just a convenient wrapper for Python's own profiler, the documentation for which is here:
http://docs.python.org/library/profile.html#module-pstats
Quoting: