dynapydantic Benchmarks¶
This page shows the results of local benchmarking of this library. Absolute performance is largely governed by pydantic-core, so the figures reported here are measurments over a hand-rolled equivalent solution.
Legend¶
- MC = Model-construction time union realization
- VT = Validation-time union realization
- Disc = Discriminated union
- Smart = Smart union
Class hierarchy creation overhead (median ± IQR) ¶
| Mode | Subclass Count | ||
|---|---|---|---|
| 5 | 25 | 100 | |
| Disc MC | 0.413 ± 0.044 ms 22.34% ± 2.41% |
1.818 ± 0.106 ms 23.29% ± 1.38% |
6.993 ± 0.261 ms 23.20% ± 0.87% |
| Disc VT | 40.688 ± 34.642 us 2.20% ± 1.87% |
0.424 ± 0.113 ms 5.44% ± 1.44% |
2.395 ± 0.605 ms 7.94% ± 2.01% |
| Disc MC Injected |
0.970 ± 0.043 ms 52.49% ± 2.43% |
4.510 ± 0.132 ms 57.78% ± 1.80% |
17.971 ± 0.452 ms 59.60% ± 1.53% |
| Disc VT Injected |
0.594 ± 0.052 ms 32.12% ± 2.87% |
3.315 ± 0.123 ms 42.47% ± 1.64% |
13.223 ± 0.304 ms 43.86% ± 1.03% |
| Smart MC | 0.298 ± 0.041 ms 17.51% ± 2.41% |
1.078 ± 0.070 ms 14.29% ± 0.93% |
3.891 ± 0.305 ms 13.16% ± 1.04% |
| Smart VT | 0.167 ± 0.030 ms 9.84% ± 1.79% |
0.593 ± 0.078 ms 7.86% ± 1.03% |
2.017 ± 0.383 ms 6.82% ± 1.30% |
Validation overhead per validation (median ± IQR; 10 subclasses) ¶
| Mode | Python (N=1) | Python (N=1000) | JSON (N=1) | JSON (N=1000) |
|---|---|---|---|---|
| Disc MC | 0.459 ± 0.358 us 8.54% ± 6.67% |
0.023 ± 0.049 us 1.15% ± 2.46% |
0.499 ± 0.325 us 9.36% ± 6.11% |
0.010 ± 0.030 us 0.52% ± 1.59% |
| Disc VT | 0.667 ± 0.008 ms 12402.33% ± 506.21% |
7.831 ± 0.088 us 394.49% ± 8.10% |
0.672 ± 0.008 ms 12596.06% ± 511.85% |
11.167 ± 0.102 us 590.28% ± 7.00% |
| Smart MC | 0.625 ± 1.266 us 3.88% ± 7.85% |
0.005 ± 0.132 us 0.04% ± 1.19% |
0.458 ± 0.502 us 3.45% ± 3.77% |
0.050 ± 0.087 us 0.55% ± 0.97% |
| Smart VT | 0.229 ± 0.003 ms 1423.13% ± 83.28% |
7.886 ± 0.164 us 70.78% ± 1.59% |
0.236 ± 0.004 ms 1777.22% ± 52.31% |
11.445 ± 0.120 us 127.38% ± 1.73% |