Python profiling with spyder: times for constituents do not sum up to a total function's time

亡梦爱人 提交于 2020-01-16 08:00:02

问题


I am profiling my python code using Spyder IDE.

As you can see in the screenshot below, it took 1.20 min = 80 sec for the _get_loglik_seq function to execute. However, the timing of various functions/procedures that constitutes this function are the following: solve_EV = 29.78s, c_get_gamma = 10.12 sec, norm = 6.57 sec, outer = 4.70 sec, <method dot ...: 2.17 sec, all others: <1 sec.

If one sums up these times, the result will be about 54 s, which is way smaller than 80s.

How is it possible? Is it a profiler bug or did I miss something? Can anyone suggest a good tool for Python code profiling? (I am working on Mac OS)

Thanks, Mikhail


回答1:


The reason is the following:

Total time = execution time of the function, including all the sub-functions.

Local time = execution time of the function without it's sub-functions.

Therefore, if a function p calls subfunctions s1, s2, s3, then:

ToTtime(p)=ToTtime(s1)+ToTtime(s1)+ToTtime(s1)+Localtime(p),

which approximately holds.



来源:https://stackoverflow.com/questions/51619282/python-profiling-with-spyder-times-for-constituents-do-not-sum-up-to-a-total-fu

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