r/Python • u/connorman528 • Aug 25 '26
Discussion Benchmarking Popular Python Runtime Type Checkers: Beartype, Typeguard, type_enforced, Pydantic
Below are benchmark results comparing the execution time of runtime type-checking tools in Python 3.14 across various data types and nested collections.
The checkers tested include Beartype (1-item sampling), Typeguard (@typechecked, 1-item sampling), type_enforced (@Enforcer 1-item sample & 100% validation), and Pydantic (@validate_call, 100% validation).
Benchmark Results
Average execution time per single function call over 100 runs (in microseconds, µs):
| Type / Structure | Beartype (1 sample) | Typeguard (1 sample) | type_enforced (1 sample) | Pydantic (100%) | type_enforced (100%) |
|---|---|---|---|---|---|
int | 0.29 µs | 2.41 µs | 0.15 µs | 1.27 µs | 0.17 µs |
Union[int, float] | 0.31 µs | 5.56 µs | 0.17 µs | 1.48 µs | 0.17 µs |
str | 0.30 µs | 2.39 µs | 0.15 µs | 1.25 µs | 0.15 µs |
dict[str, int] (5 keys) | 0.46 µs ⚠️ | 4.98 µs ⚠️ | 0.27 µs ⚠️ | 1.75 µs | 0.40 µs |
dict[str, int] (1,000 keys) | 0.46 µs ⚠️ | 4.97 µs ⚠️ | 0.27 µs ⚠️ | 81.49 µs | 27.50 µs |
dict[str, int] (10,000 keys) | 0.45 µs ⚠️ | 5.14 µs ⚠️ | 0.27 µs ⚠️ | 881.63 µs | 278.38 µs |
list[int] (5 items) | 0.41 µs ⚠️ | 3.76 µs ⚠️ | 0.18 µs ⚠️ | 1.49 µs | 0.26 µs |
list[int] (1,000 items) | 0.52 µs ⚠️ | 3.72 µs ⚠️ | 0.18 µs ⚠️ | 22.49 µs | 12.57 µs |
list[int] (10,000 items) | 0.61 µs ⚠️ | 3.72 µs ⚠️ | 0.18 µs ⚠️ | 212.59 µs | 122.58 µs |
list[Union[int, float]] (5 items) | 0.48 µs ⚠️ | 4.68 µs ⚠️ | 0.18 µs ⚠️ | 1.86 µs | 0.33 µs |
list[Union[int, float]] (1,000 items) | 0.58 µs ⚠️ | 4.87 µs ⚠️ | 0.19 µs ⚠️ | 106.14 µs | 12.60 µs |
list[Union[int, float]] (10,000 items) | 0.67 µs ⚠️ | 4.88 µs ⚠️ | 0.18 µs ⚠️ | 1,062.99 µs | 122.87 µs |
list[dict[str, int]] (5 × 5 items) | 0.59 µs ⚠️ | 6.27 µs ⚠️ | 0.30 µs ⚠️ | 3.80 µs | 1.39 µs |
list[dict[str, int]] (100 × 10 items) | 0.69 µs ⚠️ | 6.31 µs ⚠️ | 0.29 µs ⚠️ | 85.05 µs | 43.68 µs |
list[dict[str, int]] (100 × 100 items) | 0.78 µs ⚠️ | 6.45 µs ⚠️ | 0.29 µs ⚠️ | 788.38 µs | 310.50 µs |
Notes on Methodology & Results
- Environment & Methodology: Tested with Python 3.14.5 on an Ubutnu 24.04 (Ryzen Threadripper 3770 with 128gb RAM). Every checker received identical test inputs and type definitions. Timings represent the average duration of a single function call over 100 executions (discarding an initial warm-up run).
- The ⚠️ Warning: Indicates that the checker did not catch an invalid item placed in the collection during test runs because the invalid element fell outside the sampled index.
Full vs. Sampled Validation:
- Full (100%) Validation (
Pydantic,type_enforced 100%): Iterates and checks every item in collections (O(N) time). - Sampled Validation (
Beartype,Typeguard,type_enforced 1-sample): Checks 1 element (O(1) time), which keeps execution flat regardless of collection size, but without full-containment safety guarantees.
- Full (100%) Validation (
I realize that there may be optimizations I missed when calling various validation decorators. Please let me know of any optimizations or other packages to try out.