# @time and @btime show different allocations

**URL:** <https://discourse.julialang.org/t/time-and-btime-show-different-allocations/58632>\
**Category:** General Usage\
**Tags:** benchmarktools, time\
**Created:** [April 5, 2021, 6:05pm UTC](https://discourse.julialang.org/t/time-and-btime-show-different-allocations/58632 "2021-04-05T18:05:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcell\_Havlik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marcell_havlik/32/37424_2.png) [@Marcell\_Havlik](https://discourse.julialang.org/u/Marcell_Havlik)\
**Post date:** [April 5, 2021, 6:05pm UTC](https://discourse.julialang.org/t/time-and-btime-show-different-allocations/58632/1 "2021-04-05T18:05:21Z")

</div>

Hey Julianners,

What can be the difference, that makes @time and @btime time different time in these scenarios?

```julia
a, b = 6, 7
foo(a, b) = begin
  for i = 1:2
    a, b=a + 6, b + 7+i
  end
end
@time foo(a,b)
@time foo(a,b)
@btime $foo($a,$b)

```

It gives:

```julia
  0.008822 seconds (17.17 k allocations: 1.149 MiB, 99.61% compilation time)
  0.000004 seconds (1 allocation: 32 bytes)
  1.555 ns (0 allocations: 0 bytes)

```

I know there is an allocation for the tuple return a,b… but why doesn’t `@btime` shows it? Or is it elliminated in some optimisation process?

I used @btime in one of my project that showed I eliminated one allocation this way in a speed intensive unit and not sure if it is just a mistake of the timing or there are still allocations?

Thank you for the answer!

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [April 5, 2021, 6:14pm UTC](https://discourse.julialang.org/t/time-and-btime-show-different-allocations/58632/2 "2021-04-05T18:14:08Z")

</div>

`@btime` throws the code you wrote in a function and ignores compilation time. There’s no allocation for the tuple except when you assign it to a global (which is what the REPL does and what `@time` is showing), assuming your function actually has a `return (a,b)` in it.

---

<div class="post-metadata">

**Author:** ![Marcell\_Havlik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marcell_havlik/32/37424_2.png) [@Marcell\_Havlik](https://discourse.julialang.org/u/Marcell_Havlik)\
**Post date:** [April 5, 2021, 7:15pm UTC](https://discourse.julialang.org/t/time-and-btime-show-different-allocations/58632/3 "2021-04-05T19:15:26Z")

</div>

Why does the @btime throw the code in this scenario? That is really not what I wanted to measure. 😃
