I’m moving my question here that I asked on github some hours ago. The issue is that one line makes my Julia-code run slower than my Matlab-code and I don’t see why or how I could solve it. In Matlab I use ( tCPU=cputime; “code” cputime-tCPU ) to calculate time and in Julia I use @time.
I’m posting my example here (Julia code) and maybe you can see if there’s something strange even if you don’t have the rest of the code. I time my function like this:
@time ip( edgesTotal,trianglesTotal,
trianglePlus,triangleMinus,center,center2)
And the function is:
function ip( edgesTotal,trianglesTotal,
trianglePlus,triangleMinus,center,center2)
gP=complex(zeros(1,9,edgesTotal)) #K complex -> g complex -> gP complex
for p=1:trianglesTotal
plus=find(trianglePlus[1:736]-p.==0)
minus=find(triangleMinus[1:736]-p.==0)
D=center2.-center[:,p]
R=sqrt.(sum(D.*D,1)) # [1 9 trianglesTotal]
g=exp(-K.*R)./R # [1 9 trianglesTotal]
gP=g[:,:,trianglePlus]
end
end
Which gives result: (notice memory allocation…)
0.943518 seconds (7.22 M allocations: 559.592 MB, 15.35% gc time)
When I comment: #gP=g[:,:,trianglePlus] I get the following result instead:
0.375961 seconds (53.91 k allocations: 294.959 MB, 6.79% gc time)
Corresponding times in Matlab:
Entire code: 0.5148
Excluding gP-line: 0.3900
The times differs a bit each time I run the code (0.1 sec difference) but these are usual values for me and as you can see it’s something strange going on in the Julia code. Is there anyone who has any idea what’s making my julia code slow?