Why is this code so slow in julia compared to a numpy implementation?

As the others said, read the performance tip, don’t use global variables, use BenchmarkTools. Your first example becomes

using BenchmarkTools
a=rand(3,3,50);
function test(a)
    for i in (1:size(a,3))
        (5.0.*a[1,:,i]+a[1,:,i]./2.0+4.0)
    end
end
@belapsed test($a) #118 us

and use triple back ticks to set off code section.

4 Likes