Why sum of the measured times of each function is not equal to the total run time?

So then your answer was


In general, there are going to be overhead when you do a time measurement and more if you print anything. And your current result will also be affected by compilation. These overhead should be small and won’t matter if you are only doing a few of them in 2 seconds as you originally claimed, i.e.

The measured time for the for loop is almost 2 second. However, the sum of measured times for f1(), f2(), f3() is less than a second!!!

from the original top post and,

But if you are just complaining about less a ms of difference in a single run, there can be a lot of boring explanations that doesn’t really worth investing deeply unless you are benchmarking either the compiler or other low level or printing code.

1 Like