Benchmarks
Criterion.rs benchmarks, algorithm comparisons, and scaling analysis.
Benchmarks
The solver uses Criterion.rs v0.5 for statistically rigorous benchmarking with HTML reports.
Running Benchmarks
# Full benchmark suite cargo bench # Specific benchmark cargo bench -- chain_solve
HTML reports are generated in target/criterion/<benchmark>/report/index.html.
Macro-Benchmarks
| Benchmark | Description | Parameters |
|---|---|---|
chain_solve | Serial distance constraints | 5 / 20 links |
grid_solve | 2D grid with horizontal + vertical | 4×4 grid |
tangent_garden_solve | Multiple tangent circles | 6 circles |
mixed_solve | Mix of all constraint types | 30 constraints |
overconstrained_solve | Redundant constraints | 2× overdetermined |
Algorithm Comparison
The headline comparison on the chain-20 benchmark:
| Algorithm | Time | Relative | Iterations |
|---|---|---|---|
| DogLeg | 2.41 ms | 1.0× | 12 |
| BFGS | 3.30 ms | 1.4× | 15 |
| L-BFGS | 3.15 ms | 1.3× | 16 |
| Sparse CG | 5.20 ms | 2.2× | 22 |
| LM | 54.8 ms | 22.7× | 48 |
DogLeg dominates on chain problems because the Gauss-Newton step is nearly exact, and the trust-region framework avoids LM's conservative damping.
Chain-5 (smaller problem)
| Algorithm | Time |
|---|---|
| DogLeg | 85.9 µs |
| BFGS | 102 µs |
| LM | 1.95 ms |
Micro-Benchmarks
Isolated measurement of individual operations:
| Benchmark | What It Measures |
|---|---|
compute_residuals | Residual vector evaluation |
compute_jacobian | Analytical Jacobian computation |
finalise | Solution extraction and verification |
These help identify bottlenecks independently of the solver algorithm.
Scaling Benchmarks
Chain problems at increasing sizes:
| Problem | Parameters | DogLeg | LM |
|---|---|---|---|
| chain-50 | 100 | 6.2 ms | 142 ms |
| chain-100 | 200 | 14.8 ms | 410 ms |
| chain-200 | 400 | 38.5 ms | 1200 ms |
DogLeg scales roughly linearly with problem size for chain problems, while LM scales superlinearly due to the dense linear system solves.
Cross-Validation Benchmark
Runs all algorithms on the same problem and compares results:
cargo bench -- cross_validation
Measures the overhead of running multiple algorithms in sequence. Typical overhead is 2–3× compared to a single algorithm.
Intelligent Multi-Start Benchmark
| Problem | Single Start | Multi-Start (20) | Best-of |
|---|---|---|---|
| chain-20 | 2.41 ms | 28.5 ms | 2.38 ms |
| tangent_garden | 5.10 ms | 62.3 ms | 3.90 ms |
Multi-start finds better solutions on problems with multiple local minima, at the cost of 10–15× runtime.
L-BFGS vs BFGS
| Problem | n | BFGS | L-BFGS (m=10) |
|---|---|---|---|
| chain-20 | 40 | 3.30 ms | 3.15 ms |
| chain-100 | 200 | 18.2 ms | 12.1 ms |
| chain-200 | 400 | 52.8 ms | 24.3 ms |
L-BFGS becomes significantly faster for n ≥ 100 due to O(mn) vs O(n²) per-iteration cost.
Stagnation Detection On/Off
| Problem | Stagnation ON | Stagnation OFF |
|---|---|---|
| chain-20 | 2.41 ms | 2.41 ms |
| overconstrained | 1.80 ms | 4.20 ms |
Stagnation detection has negligible overhead on well-conditioned problems but dramatically speeds up pathological cases by terminating early.
Performance Metrics Overhead
Enabling tracing and diagnostics adds ~5% overhead:
| Mode | chain-20 |
|---|---|
| No tracing | 2.41 ms |
| With tracing | 2.53 ms |
| Full diagnostics | 2.58 ms |
Baseline Report
A baseline benchmark report is maintained at:
benchmarks/BASELINE.md
CI runs benchmarks and compares against the baseline. Regressions larger than 10% trigger a warning.