# Weird results while trying to measure allocation :/

**URL:** <https://discourse.julialang.org/t/weird-results-while-trying-to-measure-allocation/117745>\
**Category:** General Usage\
**Tags:** memory-allocation, potential-bug, measurements, allocations\
**Created:** [August 1, 2024, 9:47pm UTC](https://discourse.julialang.org/t/weird-results-while-trying-to-measure-allocation/117745 "2024-08-01T21:47:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [August 1, 2024, 9:47pm UTC](https://discourse.julialang.org/t/weird-results-while-trying-to-measure-allocation/117745/1 "2024-08-01T21:47:02Z")

</div>

Consider this Julia program:

```julia
f() = Vector{Int}(undef, 128*1024*1024)
(@timed f()).bytes
(r = @timed f()); r.bytes

```

Why do recent versions of Julia (v1.8 and up) evaluate the second line as `0`? It really seems like the second and third line should be equivalent. This is the result for v1.11:

```julia-repl
julia> f() = Vector{Int}(undef, 128*1024*1024)
f (generic function with 1 method)

julia> (@timed f()).bytes
0

julia> (r = @timed f()); r.bytes
1073741888

```

I guess Julia compiles the entire expression `(@timed f()).bytes`, figures out the allocations are unnecessary, and eliminates them?

---

<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:** [August 2, 2024, 12:19am UTC](https://discourse.julialang.org/t/weird-results-while-trying-to-measure-allocation/117745/2 "2024-08-02T00:19:16Z")

</div>

Curiously it is related to the vector being intitalized with `undef`:

```julia-repl
julia> f() = zeros(Int, 128*1024*1024)
f (generic function with 1 method)

julia> (@timed f()).bytes
1073741888

julia> (r = @timed f()); r.bytes
1073741888

```
