I see. So you use explicit @inbounds
or none at all, but never start Julia with --check-bounds=no
? How come I see a large difference between functions optE
and optEib
?
function optE(A)
for idx in CartesianIndices(A)
i, j, k = Tuple(idx)
A[idx] = f(i, g(j, k))
end
end
function optEib(A)
for idx in CartesianIndices(A)
i, j, k = Tuple(idx)
@inbounds A[idx] = f(i, g(j, k))
end
end
julia> @benchmark optE(A)
BenchmarkTools.Trial:
memory estimate: 0 bytes
allocs estimate: 0
--------------
minimum time: 4.376 ms (0.00% GC)
median time: 4.516 ms (0.00% GC)
mean time: 4.578 ms (0.00% GC)
maximum time: 6.253 ms (0.00% GC)
--------------
samples: 1092
evals/sample: 1
julia> @benchmark optEib(A)
BenchmarkTools.Trial:
memory estimate: 0 bytes
allocs estimate: 0
--------------
minimum time: 2.946 ms (0.00% GC)
median time: 3.239 ms (0.00% GC)
mean time: 3.259 ms (0.00% GC)
maximum time: 4.865 ms (0.00% GC)
--------------
samples: 1534
evals/sample: 1