Don’t benchmark with non-const global variables.
function bench_svector(M, n_steps)
for step in 1:n_steps
delta_M = step / n_steps
out = M .+ (SVector(delta_M, delta_M),)
end
end
function bench_matrix(M, n_steps)
for step in 1:n_steps
delta_M = step / n_steps
out = M .+ delta_M
end
end
julia> @btime bench_svector(M, 10^5)
2.988 ms (100000 allocations: 10.68 MiB)
julia> @btime bench_matrix(M, 10^5)
3.254 ms (100000 allocations: 10.68 MiB)