Benchmarks¶
The benchmark script can be found in the
bench folder.
It compares diffsol-jax against
diffrax, since that is the choice a
JAX user actually faces. Both libraries solve the same models at the same
tolerances over the same output times, in float64.
As an overall summary:
- Stiff problems: use diffsol-jax. On Robertson it is ~7 times faster at
batch size 1 and ~29 times faster at larger batches, with similar margins on
the gradient. (diffrax has no BDF method, so the comparison is against
Kvaerno5.) - Small non-stiff problems: use diffrax. At batch size 1 it is ~14--32 times faster. Every call into diffsol-jax costs a few microseconds of fixed overhead, which for a two-state system is the whole runtime; diffrax compiles the entire solve with XLA and pays none of that.
- Larger or heavily batched non-stiff problems: roughly even, tipping to diffsol-jax as either the state or the batch grows, since the fixed overhead is amortised over more work per call.
Info
These are small benchmarks, run on one machine, meant to show where each library is the better choice rather than to settle anything. They also compare at a single pair of tolerances; a work-precision diagram, sweeping tolerances and plotting achieved error against time, would say more.
For diffsol itself measured against other solver implementations, see the diffsol benchmarks.
Results¶
Times are medians in milliseconds. "faster" is the ratio between the two,
naming diffrax when it wins. A * marks a noisy cell (interquartile range over
15% of the median).
| model | methods | B | solve | diffrax | faster | grad | diffrax | faster |
|---|---|---|---|---|---|---|---|---|
| Robertson (stiff) | bdf / Kvaerno5 | 1 | 0.772 | 5.44 | 7x | 3.42 | 26 | 7.6x |
| Robertson (stiff) | bdf / Kvaerno5 | 64 | 2.25 | 64.3 | 29x | 17.3 | 315 | 18x |
| Robertson (stiff) | bdf / Kvaerno5 | 1024 | 32.9 | 960 | 29x | 163 | 3816 | 23x |
| Lotka-Volterra | tsit45 / Tsit5 | 1 | 2.29 | 0.0705 * | diffrax 32x | 6.57 | 0.255 | diffrax 26x |
| Lotka-Volterra | tsit45 / Tsit5 | 64 | 4.45 | 1.71 | diffrax 2.6x | 23.7 | 9.59 | diffrax 2.5x |
| Lotka-Volterra | tsit45 / Tsit5 | 1024 | 53.9 | 27.3 | diffrax 2x | 166 | 160 | ~equal |
| oscillators N=4 | tsit45 / Tsit5 | 1 | 1.63 | 0.0844 * | diffrax 19x | 4.7 | 0.332 * | diffrax 14x |
| oscillators N=4 | tsit45 / Tsit5 | 64 | 9.41 | 3.27 | diffrax 2.9x | 29.8 | 15.1 | diffrax 2x |
| oscillators N=4 | tsit45 / Tsit5 | 1024 | 64.7 | 60.3 | ~equal | 237 | 331 | 1.4x |
| oscillators N=32 | tsit45 / Tsit5 | 1 | 1.51 | 0.107 * | diffrax 14x | 5 | 0.647 * | diffrax 7.7x |
| oscillators N=32 | tsit45 / Tsit5 | 64 | 21.9 | 21.8 | ~equal | 97.7 * | 120 | 1.2x |
| oscillators N=32 | tsit45 / Tsit5 | 1024 | 263 | 488 | 1.9x | 1158 * | 2004 | 1.7x |
The two solutions agree to roughly the solver tolerances -- the check that the times above are comparable at all: Robertson 3.1e-6, Lotka-Volterra 5.4e-5, oscillators 7.7e-7 (N=4) and 5.4e-7 (N=32), each relative to the scale of the solution.
Measured on an AMD Ryzen 7 PRO 7840U (16 CPUs, Linux 6.18) on 2026-11-29, with
diffsol-jax efe9ec4, jax 0.12.0.1 and diffrax 0.7.2.
Method¶
Three models, chosen to separate the cases above:
- Robertson: chemical kinetics, stiff, three states.
- Lotka-Volterra: non-stiff, two states.
- oscillators: a chain of N nonlinear oscillators, 2N states, non-stiff.
Both libraries use the same Tsit5 tableau (
tsit45in diffsol).
B is the number of parameter sets solved at once, batched with jax.vmap in
both libraries. The gradient is of sum(ys[..., 0]) with respect to the
parameters, through each library's default reverse-mode path. Tolerances are
rtol=1e-6, atol=1e-8. Each cell runs in its own subprocess, and times are
the median of at least five runs after a warm-up run that absorbs compilation.
Running it¶
This prints the table and writes the raw timings to bench/results.json.
--models, --lanes and --oscillators restrict the matrix, and
--render bench/results.json reprints the table from a previous run.