问题
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