如何读取IPython%prun(profiler)命令的输出?

2024-04-26 23:37:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我运行这个:

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)

--剪--

每次都做什么,珀考尔,卡姆时间?ncalls相当明显(调用函数的次数)。我的猜测是tottime是在函数中花费的总时间,不包括在它自己的函数调用中花费的时间;percall是???;cumtime是在函数调用中花费的总时间,包括在其自身函数调用中花费的时间(当然,不包括重复计数)。docs没有太大帮助;Google搜索也没有帮助。


Tags: inmy时间functioncpu花费函数调用calls
1条回答
网友
1楼 · 发布于 2024-04-26 23:37:49

它只是Python自己的profiler的一个方便的包装器,文档如下:

http://docs.python.org/library/profile.html#module-pstats

引用:

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

相关问题 更多 >