![](/img/trans.png)
[英]How do I assign the result of iPython profiler %%prun -r to a variable?
[英]How do I read the output of the IPython %prun (profiler) command?
我运行这个:
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)
--剪辑--
tottime、percall 和 cumtime 各做什么? ncalls 相当明显(调用 function 的次数)。 我的猜测是 tottime 是在 function 中花费的总时间,不包括在其自己的 function 调用中花费的时间; percall 是???; cumtime 是在 function 调用中花费的总时间,包括在其自己的 function 调用中花费的时间(当然,不包括重复计算)。 文档不太有用; 谷歌搜索也无济于事。
它只是 Python 自己的分析器的一个方便的包装器,其文档在这里:
http://docs.python.org/library/profile.html#module-pstats
报价:
ncalls调用次数,
在给定function中花费的总时间的总时间(不包括调用子函数的时间),
percall是 tottime 除以 ncalls 的商
cumtime是在这个和所有子函数中花费的总时间(从调用到退出)。 即使对于递归函数,这个数字也是准确的。
percall是 cumtime 除以原始调用的商
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.