Skip to content

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.438 ± 0.070 ms
18.93% ± 3.05%
1.909 ± 0.116 ms
19.20% ± 1.18%
7.243 ± 0.417 ms
18.80% ± 1.09%
Disc VT -59.396 ± 57.477 us
-2.56% ± 2.48%
61.480 ± 106.507 us
0.62% ± 1.07%
0.764 ± 0.418 ms
1.98% ± 1.08%
Disc MC
Injected
0.991 ± 0.062 ms
42.76% ± 2.82%
4.966 ± 0.132 ms
49.94% ± 1.38%
19.138 ± 0.421 ms
49.68% ± 1.17%
Disc VT
Injected
0.549 ± 0.059 ms
23.70% ± 2.58%
2.991 ± 0.124 ms
30.08% ± 1.27%
12.351 ± 0.514 ms
32.06% ± 1.36%
Smart MC 0.303 ± 0.056 ms
14.00% ± 2.57%
1.270 ± 0.322 ms
13.05% ± 3.31%
4.199 ± 2.273 ms
11.05% ± 5.98%
Smart VT 0.281 ± 0.300 ms
12.97% ± 13.85%
92.812 ± 155.072 us
0.95% ± 1.59%
0.712 ± 0.378 ms
1.87% ± 0.99%

Validation overhead per validation (median ± IQR; 10 subclasses)

Mode Python (N=1) Python (N=1000) JSON (N=1) JSON (N=1000)
Disc MC 0.418 ± 0.324 us
7.38% ± 5.74%
0.041 ± 0.032 us
2.03% ± 1.58%
0.375 ± 0.301 us
6.67% ± 5.35%
0.028 ± 0.030 us
1.43% ± 1.55%
Disc VT 0.888 ± 0.011 ms
15677.59% ± 714.44%
8.072 ± 0.072 us
397.82% ± 5.59%
0.888 ± 0.010 ms
15785.18% ± 501.44%
11.511 ± 0.229 us
589.69% ± 13.19%
Smart MC 0.250 ± 0.742 us
1.53% ± 4.56%
0.080 ± 0.200 us
0.70% ± 1.74%
0.708 ± 0.569 us
5.04% ± 4.05%
0.022 ± 0.140 us
0.23% ± 1.47%
Smart VT 0.422 ± 0.008 ms
2591.76% ± 105.40%
8.032 ± 0.176 us
70.05% ± 1.74%
0.428 ± 0.009 ms
3048.14% ± 105.74%
11.315 ± 0.227 us
118.71% ± 2.92%