# Tweaking @btime

**URL:** <https://discourse.julialang.org/t/tweaking-btime/70090>\
**Category:** General Usage\
**Tags:** question, benchmark, benchmarktools\
**Created:** [October 20, 2021, 12:41pm UTC](https://discourse.julialang.org/t/tweaking-btime/70090 "2021-10-20T12:41:01Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giulio\_Benedetti](https://avatars.discourse-cdn.com/v4/letter/g/f0a364/32.png) [@Giulio\_Benedetti](https://discourse.julialang.org/u/Giulio_Benedetti)\
**Post date:** [October 20, 2021, 12:41pm UTC](https://discourse.julialang.org/t/tweaking-btime/70090/1 "2021-10-20T12:41:01Z")

</div>

Hello!

The docs of the macro ‘@btime’ says:

> The printed time is the minimum elapsed time measured during the benchmark.

Is there a way to make the macro ‘@btime’ print the mean execution time instead of the minimum?

Thanks!

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [October 20, 2021, 1:02pm UTC](https://discourse.julialang.org/t/tweaking-btime/70090/2 "2021-10-20T13:02:41Z")

</div>

> [@Giulio\_Benedetti](#):
>
> Is there a way to make the macro ‘@btime’ print the mean execution time instead of the minimum?

No, it’s hard-coded. However, you can easily [copy the `macro btime` definition](https://github.com/JuliaCI/BenchmarkTools.jl/blob/104f4c1e210da1933ace369d6db1393cf23ac102/src/execution.jl#L559-L578) and write your own if you want, or just call `@benchmark` and get all the statistics.

The [basic argument for preferring the minimum](https://arxiv.org/abs/1608.04295) time is that external noise in the timing measurements is always positive.

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [October 20, 2021, 1:04pm UTC](https://discourse.julialang.org/t/tweaking-btime/70090/3 "2021-10-20T13:04:14Z")

</div>

I think this already exists here

[https://github.com/JuliaCI/BenchmarkTools.jl/](https://github.com/JuliaCI/BenchmarkTools.jl/)

EDIT: Ah I guess if you specifically wanted it in `@btime` then yes see the post below

---

<div class="post-metadata">

**Author:** ![mcabbott](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcabbott/32/6603_2.png) [@mcabbott](https://discourse.julialang.org/u/mcabbott)\
**Post date:** [October 20, 2021, 1:05pm UTC](https://discourse.julialang.org/t/tweaking-btime/70090/4 "2021-10-20T13:05:02Z")

</div>

See [#258](https://github.com/JuliaCI/BenchmarkTools.jl/pull/258), although “in addition to” not “instead of”.

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [October 20, 2021, 1:11pm UTC](https://discourse.julialang.org/t/tweaking-btime/70090/5 "2021-10-20T13:11:51Z")

</div>

Isn’t the median a better estimator than the mean when the distribution is (possibly very) skewed?

---

<div class="post-metadata">

**Author:** ![mcabbott](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcabbott/32/6603_2.png) [@mcabbott](https://discourse.julialang.org/u/mcabbott)\
**Post date:** [October 20, 2021, 1:28pm UTC](https://discourse.julialang.org/t/tweaking-btime/70090/6 "2021-10-20T13:28:41Z")

</div>

The argument for mean is that this seems the simplest way to get some idea of the cost of allocations. Assuming your function will ultimately be called many times. The reported GC time is much smaller than this.

The PR doesn’t propose that this as a great choice for the only number to look at, only that it’s an informative complement to the minimum.

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [October 20, 2021, 1:44pm UTC](https://discourse.julialang.org/t/tweaking-btime/70090/7 "2021-10-20T13:44:16Z")

</div>

In code that allocates, I think the mean is the best estimator of throughput.

---

<div class="post-metadata">

**Author:** ![Giulio\_Benedetti](https://avatars.discourse-cdn.com/v4/letter/g/f0a364/32.png) [@Giulio\_Benedetti](https://discourse.julialang.org/u/Giulio_Benedetti)\
**Post date:** [October 20, 2021, 2:43pm UTC](https://discourse.julialang.org/t/tweaking-btime/70090/8 "2021-10-20T14:43:56Z")

</div>

Alright, thanks a lot for all the hints! 🙂

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [October 22, 2021, 9:34am UTC](https://discourse.julialang.org/t/tweaking-btime/70090/9 "2021-10-22T09:34:08Z")

</div>

Since it hasn’t been explicitly mentioned, note that you get a lot more data (the entire histogram, even) with `@benchmark`.
