Skip to main content

2 posts tagged with "benchmarking"

benchmarking tag description

View All Tags

Pydantic vs. Dataclasses speed comparison

· 6 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

While both Pydantic models and Python dataclasses serve to structure data, their performance characteristics are significantly different. The key distinction lies in when and how validation occurs. Dataclasses rely on simple Python object initialization, while Pydantic executes a comprehensive validation and coercion pipeline on every instantiation.

The clear winner in terms of raw execution speed is the Python Dataclass.

How to Measure Execution Time of a Function in Python (With Examples)

· 6 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

Measuring how long your Python code takes to run is a critical skill for performance optimization, profiling, or benchmarking different approaches to solving a problem. Python offers many tools for tracking the execution time of a function - from simple built-in methods to full-blown profilers.

In this guide, we will explore multiple methods with code examples to help you choose the right one for your use case.