# How to benchmark append!?

**URL:** https://discourse.julialang.org/t/how-to-benchmark-append/47272
**Category:** General Usage
**Created:** [September 25, 2020, 3:56pm UTC](https://discourse.julialang.org/t/how-to-benchmark-append/47272 "2020-09-25T15:56:03Z")
**Posts on this page:** 1
**Showing post:** 7

<div class="post-metadata">

### Author: ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)
#### Post date: [September 25, 2020, 4:18pm UTC](https://discourse.julialang.org/t/how-to-benchmark-append/47272/7 "2020-09-25T16:18:24Z")

</div>

You also need to set `evals=1` (see: [BenchmarkTools setup isn't run between each iteration? - #4 by rdeits](https://discourse.julialang.org/t/benchmarktools-setup-isnt-run-between-each-iteration/36258/4) ) otherwise you will get unpredictable behavior due to re-use of the setup value between evaluations.

With that change, using `resize` is the fastest option, which is what you would expect:

```julia
julia> begin
              print("push! :"); @btime f!(xf) setup = xf=[0] evals = 1
              print("append!:"); @btime g!(xf) setup = xf=[0] evals = 1
              print("new vec:"); @btime h(xf) setup = xf=[0] evals = 1
              print("resize :"); @btime k!(xf) setup = xf=[0] evals = 1
              end
push! : 520.000 ns (6 allocations: 2.13 KiB)
append!: 106.000 ns (2 allocations: 1.67 KiB)
new vec: 89.000 ns (1 allocation: 896 bytes)
resize : 75.000 ns (1 allocation: 816 bytes)

```

---

_[View the full topic](https://discourse.julialang.org/t/how-to-benchmark-append/47272)._
