Hello Julia community,
I need help with speeding up an inner loop in a larger project (running on Julia 1.5.0). Here is a MWE. The loop accumulates multiplicatively into a vector.
using BenchmarkTools
function signal1(k,om,t)
V = ones(Float64,size(t))
for p = 1:length(om)
@. V *= 1 - k[p]*sin(om[p]*t)^4
end
return V
end
N = 200 # typically > 50_000
nt = 101 # typically 200-500
k = rand(N,N)
om = rand(N,N)
t = collect(range(0,0.5,length=nt))
@btime signal1($k,$om,$t);
The code appears type stable according to @code_warntype
. Adding @simd
or @inbounds
to the loop makes no difference. @btime
shows only one memory allocation, so the @.
macro appears to be working.
As is, this is already 9x faster than my original Matlab version - impressive! However, I am wondering whether I am leaving performance on the table. Are there any ways to speed this up, without destroying readability?
Thanks.
EDIT: remove V
from function argument list.