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

**URL:** <https://discourse.julialang.org/t/why-sum-of-the-measured-times-of-each-function-is-not-equal-to-the-total-run-time/45261>\
**Category:** General Usage\
**Created:** [August 20, 2020, 10:24am UTC](https://discourse.julialang.org/t/why-sum-of-the-measured-times-of-each-function-is-not-equal-to-the-total-run-time/45261 "2020-08-20T10:24:46Z")\
**Posts on this page:** 1\
**Page:** 2

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [August 21, 2020, 12:47am UTC](https://discourse.julialang.org/t/why-sum-of-the-measured-times-of-each-function-is-not-equal-to-the-total-run-time/45261/21 "2020-08-21T00:47:03Z")

</div>

So then your answer was

> [@Nova](#):
>
> I use tic-toc to measure time. I guess it includes the compilation time as well.

And

> [@pixel27](#):
>
> On my machine I’m seeing around 3000ns to 4000ns of overhead which would be the calls to `time_ns()` along with the math (addition/subtraction) to track the times. BTW `println` if fairly “expensive” so if you are printing the time inside the loop that will add more overhead to the loop. On my machine uncommenting the `println` (s) inside the loop boost the overhead to a bit over 2 million nano seconds.

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,

> [@Nova](#):
>
> N is small (e.g 5)

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.

[Previous page](https://discourse.julialang.org/t/why-sum-of-the-measured-times-of-each-function-is-not-equal-to-the-total-run-time/45261.md?page=1)
