Pet*_*r D 30 python profiler interpreter ipython
我运行这个:
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)
Run Code Online (Sandbox Code Playgroud)
--snip--
每次tottime,percall,cumtime是什么?ncalls相当明显(调用函数的次数).我的猜测是,tottime是在函数中花费的总时间,不包括在其自己的函数调用中花费的时间; percall是???; cumtime是在函数调用中花费的总时间,包括在其自己的函数调用中花费的时间(当然,不包括重复计数).该文档是不是太有帮助; 谷歌搜索也没有帮助.
Tho*_*s K 33
它只是Python自己的探查器的一个方便的包装器,其文档在这里:
http://docs.python.org/library/profile.html#module-pstats
引用:
ncalls 表示通话次数,
在给定函数中花费的总时间的tottime(并且不包括调用子函数所花费的时间),
percall是tottime除以ncalls的商
cumtime是在这个和所有子功能中花费的总时间(从调用到退出).即使对于递归函数,该数字也是准确的.
percall是cumtime除以原始调用的商