Why does the round.(Int, x::SVector)
allocate?
using BenchmarkTools, StaticArrays
x = SVector{2}([0., 1.])
@btime round.(Int, $x) # 21.180 ns (1 allocation: 16 bytes)
@btime round.(Int, $(x.data)) # 6.451 ns (0 allocations: 0 bytes)
julia> versioninfo()
Julia Version 1.7.0
Commit 3bf9d17731 (2021-11-30 12:12 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Xeon(R) CPU E5-2630 v3 @ 2.40GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-12.0.1 (ORCJIT, haswell)
Environment:
JULIA = /home/jmlim/appl/julia-1.7.0/bin/julia
(@v1.7) pkg> status StaticArrays
Status `~/.julia/environments/v1.7/Project.toml`
[90137ffa] StaticArrays v1.2.13
and also with StaticArrays v1.3.4