julia> a = zeros(4, 4, 3)
julia> @btime @views $a[:, :, 2] .= $a[:, :, 2]
38.862 ns (1 allocation: 192 bytes)
julia> @btime @views for i in eachindex($a[:, :, 2])
$a[:, :, 2][i] = $a[:, :, 2][i]
end
7.744 ns (0 allocations: 0 bytes)
I thought these two benchmarks do the exactly same thing.
Is this problem a bug or a specification or my wrong?
Can someone please tell me what’s going on?