5 ms·
Tarrosion is right, on my machine, putting the code inside a function is 10X faster, and then swapping the order of the loops gives another 10X improvement:
by ced 10y ago
Tarrosion is right, on my machine, putting the code inside a function is 10X faster, and then swapping the order of the loops gives another 10X improvement:
function f(s)
a=ones(s,s);
b=ones(s,s);
c=zeros(s,s);
tic();
for j in 1:s
for i in 1:s
c[i,j]=a[i,j]*b[i,j]
end
end
toc();
return c
end
Note that you also might have to run the function twice, because the first time JIT-compilation kicks in.
Julia 0.5 also now automatically devectorizes some code (eg. x = a .* b .+ c) so that you don't have to write explicit loops to get performance benefits.
- dagw 10y agoThanks. To both you and Tarrosion. Guess I need to take some time at some point to sit down and actually learn 'proper' Julia.