How do I read the output of the IPython %prun (profiler) command?

流过昼夜 提交于 2019-11-29 10:46:11

问题


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.


回答1:


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:

ncalls for the number of calls,

tottime for the total time spent in the given function (and excluding time made in calls to sub-functions),

percall is the quotient of tottime divided by ncalls

cumtime is the total time spent in this and all subfunctions (from invocation till exit). This figure is accurate even for recursive functions.

percall is the quotient of cumtime divided by primitive calls



来源:https://stackoverflow.com/questions/7069733/how-do-i-read-the-output-of-the-ipython-prun-profiler-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!