dataclass vs pydantic: python version performance

published: August 3, 2025 β€’

Overview

python 3.13 introduced significant performance improvements for dataclasses. this benchmark tracks performance evolution from python 3.10 through 3.14.

Methodology

three operations tested with 10,000 iterations each:

  • creation: object instantiation
  • modification: attribute updates
  • serialization: conversion to dictionary

Test Implementation

# Example test structure
@dataclass
class PersonDataclass:
    name: str
    age: int
    email: str
    active: bool = True

class PersonPydantic(BaseModel):
    name: str
    age: int
    email: str
    active: bool = True

timing via time.perf_counter(). complete benchmark: benchmark.py

Results

Performance comparison across Python versions

Summary

  • python 3.13 improved dataclass creation by 3x and serialization by 4x
  • pydantic performance remained consistent across versions
  • pydantic’s serialization advantage decreased from 6x to 1.3x

Performance Data

pythonoperationdataclasses (ΞΌs)pydantic (ΞΌs)relative
3.10creation0.900.850.9x
modification2.021.941.0x
serialization4.480.770.2x
3.13creation0.330.852.6x
modification1.561.751.1x
serialization1.010.700.7x
3.14creation0.330.932.8x
modification1.471.801.2x
serialization1.040.790.8x

lower times indicate better performance. relative = pydantic / dataclass

Scripts

Recommendations

  • on python 3.13+, performance differences are minimal - choose based on features
  • for serialization-heavy workloads, pydantic maintains an advantage
  • for simple data containers, dataclasses offer excellent performance with no dependencies

Notes

  • python 3.14 requires pydantic 2.12.0a1 or later (pre-release)
  • all benchmarks run on identical hardware
  • measurements include all overhead (validation, type checking)

See Also

══════════════════════════════════════════════════════════════════
on this page