Validator benchmarks¶
Micro-benchmarks for Validator.validate() / validate_batch() over
representative contract shapes, with two baselines: a hand-written
Pydantic model (what you would write without pycharter) and the
Validator's own compiled model called directly (isolates the
validate() wrapper overhead from Pydantic itself).
Numbers are machine-dependent — treat relative ratios, not absolute times, as the signal. Shapes differ in field count, so compare each benchmark to the baselines, not to each other.
Results¶
| Benchmark | Median | Mean | Ops/s | Rounds |
|---|---|---|---|---|
test_baseline_raw_pydantic |
0.69 µs | 0.70 µs | 1,433,298 | 83,633 |
test_baseline_generated_model |
0.69 µs | 0.70 µs | 1,423,971 | 137,761 |
test_validate_rule_heavy |
0.78 µs | 0.79 µs | 1,260,107 | 136,557 |
test_validate_flat |
1.13 µs | 1.14 µs | 876,162 | 34,392 |
test_validate_nested |
1.41 µs | 1.43 µs | 701,315 | 77,054 |
test_validate_coercion_heavy |
2.30 µs | 2.32 µs | 430,836 | 33,732 |
test_validate_batch_1k_flat |
1.08 ms | 1.81 ms | 553 | 607 |
Environment¶
- CPU: Intel(R) Core(TM) Ultra 7 255H
- Python: 3.13.9
- Captured: 2026-06-07T02:27:38.013453+00:00
- pytest-benchmark: 5.2.3
Regenerate¶
pytest benchmarks --benchmark-json=/tmp/bench.json
python scripts/render_benchmarks.py \
--input /tmp/bench.json --output docs/operations/benchmarks.md
Benchmarks live in benchmarks/ — outside the default pytest run
and never part of CI gates. A workflow_dispatch GitHub Actions job
(benchmarks.yml) runs them on demand and uploads the JSON report as
an artifact.