Closed
Description
using ModelingToolkit, OrdinaryDiffEq
@variables t u(t)[1:10] = 1
u = collect(u)
eqs = Differential(t).(u) .~ (1:length(u))
@named sys = ODESystem(eqs,t,u,[]; tspan=(0, 10))
prob = ODEProblem(sys)
sol = solve(prob, Tsit5(), tstops=range(prob.tspan...; length=10000))
using BenchmarkTools
@btime getindex($sol, $u);
# 1.649 s (12584906 allocations: 1.47 GiB)
Seems to scale roughly linearly with the length of the solution
sol = solve(prob, Tsit5(), tstops=range(prob.tspan...; length=100))
@btime getindex($sol, $u);
# 15.070 ms (124909 allocations: 15.01 MiB)
Indexing the solution with 10 separate scalar symbols is reasonably fast. Not exactly a 1:1 comparison, but this should give a reasonable order of magnitude for the expected speed.
sol = solve(prob, Tsit5(), tstops=range(prob.tspan...; length=10000))
@btime getindex.($(Ref(sol)), $u);
# 312.833 μs (1259 allocations: 932.17 KiB)