What is the difference between tottime and cumtime in a python script profiled with cProfile?

北慕城南 提交于 2019-12-03 09:17:47

tottime is the total time spent in the function alone. cumtime is the total time spent in the function plus all functions that this function called.

The two values is going to be the same if a function never calls anything else. For example, {waitKey} doesn't appear to invoke anything else:

  459    2.381    0.005    2.381    0.005 {waitKey}

but getPacket() calls other functions, so it's cumtime column includes the time for those calls:

 2142    2.964    0.001    4.663    0.002 load_aerdat3.py:61(getPacket)

The main.py line covers all code run outside of functions, the global code; just the statements at that level took 4.674 seconds to run, but because those statements called other functions, the total cumulative time of the main.py code plus all function calls made is 13.598 seconds.

From the documentation:

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

[...]

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

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