First thing I caught in your code http://docs.julialang.org/en/release-0.4/manual/performance-tips/#avoid-changing-the-type-of-a-variable
make bar non-type-changing 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 Second, Julia checks array bounds so @inbounds macro before for-loop should help improve performance. In some situation @simd may emit vector instructions thus faster code.