Как прочитать вывод команды IPython% prun (profiler)?
Я запускаю это:
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 довольно очевидно (количество раз, когда функция вызывается). Мое предположение заключается в том, что tottime - это общее время, затрачиваемое на выполнение функции, исключая время, затрачиваемое на его собственные вызовы функций; percall -???; cumtime - это общее время, затрачиваемое на вызов функции, включая время, потраченное на его собственные вызовы функций (но, конечно, исключая двойной счет). docs не слишком полезны; Поиск Google не помогает.
Ответы
Ответ 1
Это просто удобная оболочка для собственного профилировщика Python, документация для которой находится здесь:
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