Solving an analytical ODE *slower* than numerical?

The documentation (Composing Ordinary Differential Equations · ModelingToolkit.jl) gives the following example to show symbolic derivatives result in higher performance vs. numerical approximation:

using BenchmarkTools

@btime solve($prob, Rodas4());
      # 251.300 μs (873 allocations: 31.18 KiB)


prob_an = ODEProblem(connected_simp, u0, (0.0,10.0), p; jac=true, sparse=true)

@btime solve($prob_an, Rodas4());
      # 142.899 μs (1297 allocations: 83.96 KiB

However, running these two examples (Julia 1.7.2 on Apple M1, native) I’m getting:

13.458 μs (206 allocations: 16.86 KiB)

And

48.125 μs (1330 allocations: 86.09 KiB)

What am I missing?

1 Like

That example is just too small for sparsity to make it faster. You need a really large system for sparsity to be helpful.

1 Like