I put your code in a file and the differential equation solving into a function:
using DifferentialEquations
f(u,p,t) = 0.98u
function bench()
u0 = 1.0
tspan = (0.0,10.0)
prob = ODEProblem(f,u0,tspan)
sol = solve(prob)
end
bench()
If I now run:
@time include("solve.jl")
I get the output:
7.717988 seconds (14.98 M allocations: 1.093 GiB, 4.67% gc time, 16.49% compilation time)
which is indeed pretty long.
If you load the package DifferentialEuqations first you get:
@time using DifferentialEquations
@time include("solve.jl")
I get 6.1s for loading the package and 1.0s for executing the code.
So the problem here is the load time of the package, which is needed only once per Julia session.
You can make this a bit faster by using the package OrdinaryDiffEq instead:
using OrdinaryDiffEq
f(u,p,t) = 0.98u
function bench()
u0 = 1.0
tspan = (0.0,10.0)
prob = ODEProblem(f,u0,tspan)
sol = solve(prob, Tsit5())
end
bench()
This takes 5.0s in total, 4.2s of this is the package load time.
Matlab is loading core packages when you start Matlab, which is different from what Julia is doing.
My machine:
julia> versioninfo()
Julia Version 1.9.0
Commit 8e630552924 (2023-05-07 11:25 UTC)
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 8 × Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-14.0.6 (ORCJIT, skylake)
Threads: 1 on 8 virtual cores
Try if Julia 1.9 improves things for you.
Furthermore try to load packages only once and keep them loaded until your work is done.
By the way, solving the differential equation after loading the package and compiling the code is fast:
julia> @time bench()
0.000078 seconds (140 allocations: 8.891 KiB)