Julia v0.6.0. I have the following snippets. I wonder why “snippet_1” is so much more efficient than the others. Is it possible to make the others as efficient as “snippet_1”? Thanks!
i_ = 40
j_ = 16
a1 = rand(i_,j_,2);
# snippet_1: 0.0005 seconds (5.20 k allocations: 302.531 KiB)
@time begin
for i in 1:i_, j in 1:j_
a1ij = a1[i,j,:]
a1[i,j,:] = rand(2) .* [1,1]
end
end
# snippet_2: 0.032269 seconds (25.43 k allocations: 1.150 MiB)
@time begin
for i in 1:i_, j in 1:j_
a1ij = a1[i,j,:]
a1[i,j,:] = rand(2) .* 1
end
end
# snippet_3: 0.030712 seconds (44.24 k allocations: 1.946 MiB)
@time begin
for i in 1:i_, j in 1:j_
a1ij = a1[i,j,:]
a1[i,j,:] = a1ij .* [1,1]
end
end
# snippet_4: 0.032377 seconds (24.79 k allocations: 1.091 MiB)
@time begin
for i in 1:i_, j in 1:j_
a1ij = a1[i,j,:]
a1[i,j,:] = a1ij .* 1
end
end