# Number of allocations

**URL:** https://discourse.julialang.org/t/number-of-allocations/34280
**Category:** New to Julia
**Created:** [February 7, 2020, 3:18am UTC](https://discourse.julialang.org/t/number-of-allocations/34280 "2020-02-07T03:18:49Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![tomtom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomtom/32/5106_2.png) [@tomtom](https://discourse.julialang.org/u/tomtom)
#### Post date: [February 7, 2020, 3:18am UTC](https://discourse.julialang.org/t/number-of-allocations/34280/1 "2020-02-07T03:18:49Z")

</div>

I have difficulties understanding the number of allocations. In the following:

```julia
const v1 = [0, 1]
const v2 = [1, 2]

fun1(x) = begin
    a = x .+ v1
    return a .* v2
end

fun2(x) = @. (x + v1) * v2

julia> @btime fun1([10, 20]);
  102.232 ns (3 allocations: 288 bytes)

julia> @btime fun2([10, 20]);
  69.386 ns (2 allocations: 192 bytes)

```

for `fun1()`, one allocation for `a` + one allocation for output, so I think there should be 2 allocations, but in fact there’re 3.  
for `fun2()`, only one allocation is needed for output, but in fact there’re 2 allocations.

where is the **extra allocation**? thanks

---

<div class="post-metadata">

### Author: ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)
#### Post date: [February 7, 2020, 3:41am UTC](https://discourse.julialang.org/t/number-of-allocations/34280/2 "2020-02-07T03:41:08Z")

</div>

Here’s a hint:

```julia
julia> @btime [10, 20]
  30.892 ns (1 allocation: 96 bytes)
2-element Array{Int64,1}:
 10
 20

```

spoiler alert:

You’re allocating memory just by passing the input array. If you don’t want to count that allocation, you need to interpolate the argument into the benchmark macro:

```julia
julia> @btime fun1($([10, 20]));
  74.942 ns (2 allocations: 192 bytes)

julia> @btime fun2($([10, 20]));
  41.787 ns (1 allocation: 96 bytes)

```
