# Wildly varying timings for round and round

**URL:** <https://discourse.julialang.org/t/wildly-varying-timings-for-round-and-round/4484>\
**Category:** General Usage\
**Created:** [June 27, 2017, 7:17am UTC](https://discourse.julialang.org/t/wildly-varying-timings-for-round-and-round/4484 "2017-06-27T07:17:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mzaffalon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mzaffalon/32/214168_2.png) [@mzaffalon](https://discourse.julialang.org/u/mzaffalon)\
**Post date:** [June 27, 2017, 7:17am UTC](https://discourse.julialang.org/t/wildly-varying-timings-for-round-and-round/4484/1 "2017-06-27T07:17:57Z")

</div>

On Julia v0.6, I `@time` and `@benchmark` `round(...) and its dot counterpart, `round.(…)``. The macro @time reports 0.6 ms for `round` and 29 ms for the dot version; the macro @benchmark shows that `round.(...)` is 3 orders of magnitude faster than reported by `@time` and 20 times faster than `round(...)`. (I understand that `round` is deprecated in v0.6.)

What is the reason for the wild variation?

```julia
julia> a = randn(100);

julia> @time round(a, 3, 2);
  0.000624 seconds (88 allocations: 12.656 KiB)

julia> @time round.(a, 3, 2);
  0.029180 seconds (3.98 k allocations: 226.429 KiB)

julia> @benchmark round(a, 3, 2)
BenchmarkTools.Trial:
  memory estimate: 12.50 KiB
  allocs estimate: 84
  --------------
  minimum time: 236.047 µs (0.00% GC)
  median time: 251.742 µs (0.00% GC)
  mean time: 261.373 µs (0.46% GC)
  maximum time: 2.891 ms (83.55% GC)
  --------------
  samples: 10000
  evals/sample: 1

julia> @benchmark round.(a, 3, 2)
BenchmarkTools.Trial:
  memory estimate: 1.89 KiB
  allocs estimate: 24
  --------------
  minimum time: 12.376 µs (0.00% GC)
  median time: 13.885 µs (0.00% GC)
  mean time: 14.815 µs (1.58% GC)
  maximum time: 2.424 ms (96.41% GC)
  --------------
  samples: 10000
  evals/sample: 1

```

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [June 27, 2017, 8:10am UTC](https://discourse.julialang.org/t/wildly-varying-timings-for-round-and-round/4484/2 "2017-06-27T08:10:07Z")

</div>

Deprecated functions are slow because they do a stacktrace lookup to see if the deprecation warning has already been printed.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [June 27, 2017, 8:12am UTC](https://discourse.julialang.org/t/wildly-varying-timings-for-round-and-round/4484/3 "2017-06-27T08:12:22Z")

</div>

You should also interpolate variables into the benchmark macros:

```julia
julia> @btime round.(a, 3, 2);
  15.034 μs (24 allocations: 1.89 KiB)

julia> @btime round.($a, 3, 2);
  6.683 μs (1 allocation: 896 bytes)

```

---

<div class="post-metadata">

**Author:** ![mzaffalon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mzaffalon/32/214168_2.png) [@mzaffalon](https://discourse.julialang.org/u/mzaffalon)\
**Post date:** [June 27, 2017, 8:13am UTC](https://discourse.julialang.org/t/wildly-varying-timings-for-round-and-round/4484/5 "2017-06-27T08:13:47Z")

</div>

I have been told that already. My apologies.
