What does it mean when the cumtimes of callees don't add up to the total cumtime of a function?
<p>I'm using <code>cProfile.Profile</code>.</p>

<p>In the output of <code>print_callees</code>, I can see that a function takes about 2 seconds of <code>cumtime</code>.</p>

<p>But when I check the output of the functions it calls, their <code>cumtime</code> don't sum up to that of the caller. Actually it's much smaller.</p>

<p>What could be the reason of this?</p>

<p>That actually makes a lot of sense: the difference is the time the code in the function, excluding the calls it makes, takes. For example:</p>

<pre><code>def foo():
    for i in range(99999):
        print 'hello'
    bar()
    baz()
</code></pre>

<p>The cumulative time of <code>foo</code> will be much larger than the sums of times of <code>bar()</code> and <code>baz</code> - it has to do the loop.</p>

python performance