From b99fdaabec53e4782eb8fed405af6a8b974d4b5c Mon Sep 17 00:00:00 2001 From: Thibaut Decombe Date: Mon, 30 Dec 2024 13:20:40 +0100 Subject: [PATCH 1/3] Move CONTRIBUTING.md to the top level --- .github/CONTRIBUTING.md => CONTRIBUTING.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/CONTRIBUTING.md => CONTRIBUTING.md (100%) diff --git a/.github/CONTRIBUTING.md b/CONTRIBUTING.md similarity index 100% rename from .github/CONTRIBUTING.md rename to CONTRIBUTING.md From a4e8c34b72b14eef96172a1fbbb8befb1ab41464 Mon Sep 17 00:00:00 2001 From: Thibaut Decombe Date: Mon, 30 Dec 2024 18:42:58 +0100 Subject: [PATCH 2/3] Add a minimal README to the benchmark modules and a `bench` extra --- benchmarks/README.md | 49 +++++++++++++++++++++++++ benchmarks/bench_encodings.py | 2 +- benchmarks/bench_validation/__main__.py | 2 +- setup.py | 21 ++++++++++- 4 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 benchmarks/README.md diff --git a/benchmarks/README.md b/benchmarks/README.md new file mode 100644 index 00000000..093d41e7 --- /dev/null +++ b/benchmarks/README.md @@ -0,0 +1,49 @@ +# Benchmarks + +Here we document how to run various performance benchmarks about +serialization, validation, struct, gc and memory usage. + +## Setup + +Benchmark dependencies are included in the dev extra so simply run this: +```bash +pip install -e ".[dev]" +``` + +If you want to run the benchmarks against pydantic v1, you'll have to explicitly +downgrade using this command: +```bash +pip install "pydantic<2" +``` + +## Running Benchmarks + +```bash +# JSON Serialization & Validation +python -m benchmarks.bench_validation + +# JSON/MessagePack serialization +python benchmarks/bench_encodings.py --protocol json +python benchmarks/bench_encodings.py --protocol msgpack + +# JSON Serialization - Large Data +python benchmarks/bench_large_json.py + +# Structs +python benchmarks/bench_structs.py + +# Garbage Collection +python benchmarks/bench_gc.py + +# Library size comparison +python benchmarks/bench_library_size.py +``` + +## Print versions of benchmarked libraries +```bash +python -m benchmarks.bench_validation --versions +python benchmarks/bench_encodings.py --protocol json --versions +python benchmarks/bench_encodings.py --protocol msgpack --versions +python benchmarks/bench_large_json.py --versions +python benchmarks/bench_structs.py --versions +``` \ No newline at end of file diff --git a/benchmarks/bench_encodings.py b/benchmarks/bench_encodings.py index a07b7e7c..4e1470fe 100644 --- a/benchmarks/bench_encodings.py +++ b/benchmarks/bench_encodings.py @@ -7,7 +7,7 @@ import importlib.metadata from typing import Any, Literal, Callable -from .generate_data import make_filesystem_data +from generate_data import make_filesystem_data import msgspec diff --git a/benchmarks/bench_validation/__main__.py b/benchmarks/bench_validation/__main__.py index 713a5943..be5ff28a 100644 --- a/benchmarks/bench_validation/__main__.py +++ b/benchmarks/bench_validation/__main__.py @@ -1,7 +1,7 @@ import argparse import json import tempfile -from ..generate_data import make_filesystem_data +from benchmarks.generate_data import make_filesystem_data import sys import subprocess diff --git a/setup.py b/setup.py index 2a92252f..6dcdc9eb 100644 --- a/setup.py +++ b/setup.py @@ -59,13 +59,32 @@ *yaml_deps, *toml_deps, ] -dev_deps = ["pre-commit", "coverage", "mypy", "pyright", *doc_deps, *test_deps] +bench_deps = [ + "cattrs", + "pydantic", + "mashumaro", + "orjson", + "ujson", + "python-rapidjson", + "pysimdjson", + "ormsgpack", +] +dev_deps = [ + "pre-commit", + "coverage", + "mypy", + "pyright", + *doc_deps, + *test_deps, + *bench_deps, +] extras_require = { "yaml": yaml_deps, "toml": toml_deps, "doc": doc_deps, "test": test_deps, + "bench": bench_deps, "dev": dev_deps, } From e06d95fd35ee20960cd285640dd077ca150eb1f7 Mon Sep 17 00:00:00 2001 From: Thibaut Decombe Date: Tue, 31 Dec 2024 00:01:21 +0100 Subject: [PATCH 3/3] Don't install bench dependencies in CI --- benchmarks/README.md | 4 ++-- setup.py | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/benchmarks/README.md b/benchmarks/README.md index 093d41e7..04b9fff0 100644 --- a/benchmarks/README.md +++ b/benchmarks/README.md @@ -5,9 +5,9 @@ serialization, validation, struct, gc and memory usage. ## Setup -Benchmark dependencies are included in the dev extra so simply run this: +Benchmark additional dependencies are included in the bench extra so you will have to run this: ```bash -pip install -e ".[dev]" +pip install -e ".[dev, bench]" ``` If you want to run the benchmarks against pydantic v1, you'll have to explicitly diff --git a/setup.py b/setup.py index 6dcdc9eb..a6e7f576 100644 --- a/setup.py +++ b/setup.py @@ -76,7 +76,6 @@ "pyright", *doc_deps, *test_deps, - *bench_deps, ] extras_require = {