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