I recently watched this video which ended in a comparison between Python+Numba vs Julia (starting around 1h:06m):
The author used multithreading to run the same function 10_000 times and concluded that Julia was slower than Numba.
I was wondering if the code could be optimized. Some of the lines could be deleted altogether, but for the sake of comparison with Numba, I kept them.
# mass spring damper function friction(v::Float64, vt::Float64) v > vt ? -3v : -3vt*sign(v) end end function simulate(x0::Float64; T = 10.0, dt = 0.0001, vt = 1.0) times = 0.0:dt:T positions = zeros(length(times)) v = 0.0 a = 0.0 x = x0 positions = x0/x0 for ii in 1:length(times) if ii == 0 continue end t = times[ii] a = friction(v, vt) - 100.0*x v = v + a * dt x = x + v * dt positions[ii] = x/x0 end (times, positions) end @time simulate(10.0); using Plots plot(simulate(10.0)...) function rep(z) Threads.@threads for i = 1:z x = simulate(10.0); end end @time rep(1) @time rep(10_000)