I am a new julia user and I am trying to get a feeling on what is the best pratice to make fast code in julia. I am mainly making element wise operations in arrays/matrices. I tried a few codes to check which one allow me to get the higher speed
fbroadcast(a,b) = a .*= b;
function fcicle(a,b)
@inbounds @simd for i in eachindex(a)
a[i] *= b[i];
end
end
a = rand(100,100);
b = rand(100,100);
@btime fbroadcast(a,b)
@btime fcicle(a,b)
Using the function with the for achieved a speed about 2x of the broadcast version. What are the differences between both cases? I would expect the broadcasting to internally loop the operations very similarly to what I did on the fcicle. Finally, is there any way of achieve the best speed with a short syntax like a .*= b?
Many thanks, Dylan