Oh my bad, this was really easy to fix! I usually do inspect the code with @code_warntype but missed to do the same this time. Lesson learned.
Now the same loop is about ~30 times faster in Julia than in Fortran, really impressive. Thank you all for the prompt comments! Bye, Mosè 2016-06-01 13:27 GMT+02:00 Lutfullah Tomak: > 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.
