# Does norm() allocate?

**URL:** <https://discourse.julialang.org/t/does-norm-allocate/112407>\
**Category:** General Usage\
**Tags:** question\
**Created:** [April 2, 2024, 9:26am UTC](https://discourse.julialang.org/t/does-norm-allocate/112407 "2024-04-02T09:26:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [April 2, 2024, 9:26am UTC](https://discourse.julialang.org/t/does-norm-allocate/112407/1 "2024-04-02T09:26:40Z")

</div>

I have the following code:

```julia
using KiteModels, StaticArrays, LinearAlgebra, BenchmarkTools
function test(vec)
    KiteModels.norm(vec)
end
vec=MVector{3}([1.0,2,3])

test(vec)
bytes=@allocated test(vec)
println("Allocate $bytes bytes!")
@benchmark test($vec)

```

The macro `@allocated` tells me my function would allocate 16 bytes, BenchmarkTools tells me I have zero allocations.

Which answer is correct?

Using LinearAlgebra.norm gives the same result, but it is slower (and more accurate).

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [April 2, 2024, 9:45am UTC](https://discourse.julialang.org/t/does-norm-allocate/112407/2 "2024-04-02T09:45:56Z")

</div>

> [@ufechner7](#):
>
> Which answer is correct?

The benchmark tools one.

---

<div class="post-metadata">

**Author:** ![barucden](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/barucden/32/26154_2.png) [@barucden](https://discourse.julialang.org/u/barucden)\
**Post date:** [April 2, 2024, 9:51am UTC](https://discourse.julialang.org/t/does-norm-allocate/112407/3 "2024-04-02T09:51:46Z")

</div>

To elaborate a little bit more, the reason is `vec` is a global non-constant variable:

```julia
const vec2 = vec
@allocated test(vec2) # should be zero

```
