Are there cases where it might be more efficient to use push
with an SVector
than to use push!
with a Vector
?
I have one benchmark below where push!
is much more efficient:
using StaticArrays
using BenchmarkTools
function foo(x)
y = SVector{0, eltype(x)}()
for v in x
y = push(y, v)
end
y
end
function bar(x)
y = Vector{eltype(x)}()
for v in x
push!(y, v)
end
y
end
x = 1:50
julia> @btime foo($x);
5.740 μs (50 allocations: 10.67 KiB)
julia> @btime bar($x);
410.457 ns (6 allocations: 1.14 KiB)