Two things:
When the function is first launched, the time will include the compilation time of the code. If you want apples to compare apples with a compiled function in Mathematica, you have to run the function twice and the second run time. With your code, I get:
elapsed time: 1.156531976 seconds (447764964 bytes allocated)
for the first run, which includes compilation time and
elapsed time: 1.135681299 seconds (447520048 bytes allocated)
, .
-, , , , . .
:
function fdtd1d_local(steps, ie = 200)
ez = zeros(ie + 1);
hy = zeros(ie);
for n in 1:steps
for i in 2:ie
ez[i]+= (hy[i] - hy[i-1])
end
ez[1]= sin(n/10)
for i in 1:ie
hy[i]+= (ez[i+1]- ez[i])
end
end
return (ez, hy)
end
fdtd1d_local(10000)
@time fdtd1d_local(10000);
Mathematica ,
{0.094005, Null}
@time fdtd1d_local:
elapsed time: 0.015188926 seconds (4176 bytes allocated)
6 . .