Ok, I revise what I said about @ simd, according to documentation, it only works for one dimensional ranges and it does not allow this type for-loop and throws error.
Here is timings for me julia> function foo() array1 = rand(70, 1000) array2 = rand(70, 1000) array3 = rand(2, 70, 20, 20) bar = 0 @time for l = 1:1000, k = 1:20, j = 1:20, i = 1:70 bar = bar + (array1[i, l] - array3[1, i, j, k])^2 + (array2[i, l] - array3[2, i, j, k])^2 end end foo (generic function with 1 method) julia> foo() 1.215454 seconds (84.00 M allocations: 1.252 GB, 4.16% gc time) julia> foo() 1.308979 seconds (84.00 M allocations: 1.252 GB, 3.92% gc time) julia> function foo() array1 = rand(70, 1000) array2 = rand(70, 1000) array3 = rand(2, 70, 20, 20) bar = 0.0 @time for l = 1:1000, k = 1:20, j = 1:20, i = 1:70 bar = bar + (array1[i, l] - array3[1, i, j, k])^2 + (array2[i, l] - array3[2, i, j, k])^2 end end foo (generic function with 1 method) julia> foo() 0.114811 seconds julia> foo() 0.150542 seconds julia> function foo() array1 = rand(70, 1000) array2 = rand(70, 1000) array3 = rand(2, 70, 20, 20) bar = 0.0 @time @inbounds for l = 1:1000, k = 1:20, j = 1:20, i = 1:70 bar = bar + (array1[i, l] - array3[1, i, j, k])^2 + (array2[i, l] - array3[2, i, j, k])^2 end end foo (generic function with 1 method) julia> foo() 0.004927 seconds