This commit is contained in:
Eden Kirin
2023-10-11 21:26:35 +02:00
parent 94559712c8
commit b4cff50e8e
3 changed files with 54 additions and 20 deletions

53
README.md Normal file
View File

@ -0,0 +1,53 @@
# Pydantic vs MsgSpec
Libs used for benchmark:
- [pydantic 2.4.2](https://docs.pydantic.dev/latest/)
- [msgspec 0.18.4](https://jcristharif.com/msgspec/index.html)
## Usage
### Install virtual environment
```
poetry install
```
### Create test data
- Edit `benchmark/factories.py` and set `COLUMNS_COUNT` and `PLANOGRAMS_COUNT` to desired size.
- Uncomment `create_test_file(TEST_DATA_FILE)` line in main.py
- Run main.py
You can comment back this line after json test file is created.
### Run benchmark
```
python main.py
```
## Results
```
*** Running PydanticBenchmark
Finished in 10.781s
*** Running MsgSpecBenchmark
Finished in 1.725s
```
```
██████╗ ██╗ ██╗██████╗ █████╗ ███╗ ██╗████████╗██╗ ██████╗
██╔══██╗╚██╗ ██╔╝██╔══██╗██╔══██╗████╗ ██║╚══██╔══╝██║██╔════╝
██████╔╝ ╚████╔╝ ██║ ██║███████║██╔██╗ ██║ ██║ ██║██║
██╔═══╝ ╚██╔╝ ██║ ██║██╔══██║██║╚██╗██║ ██║ ██║██║
██║ ██║ ██████╔╝██║ ██║██║ ╚████║ ██║ ██║╚██████╗
╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═╝ ╚═╝ ╚═════╝
██╗ ██╗ ██████╗ ██╗ ██╗ ███████╗██╗ ██╗ ██████╗██╗ ██╗ ██████╗ █████╗ ██╗ ██╗ ███████╗
╚██╗ ██╔╝██╔═══██╗██║ ██║ ██╔════╝██║ ██║██╔════╝██║ ██╔╝ ██╔══██╗██╔══██╗██║ ██║ ██╔════╝
╚████╔╝ ██║ ██║██║ ██║ ███████╗██║ ██║██║ █████╔╝ ██████╔╝███████║██║ ██║ ███████╗
╚██╔╝ ██║ ██║██║ ██║ ╚════██║██║ ██║██║ ██╔═██╗ ██╔══██╗██╔══██║██║ ██║ ╚════██║
██║ ╚██████╔╝╚██████╔╝ ███████║╚██████╔╝╚██████╗██║ ██╗ ██████╔╝██║ ██║███████╗███████╗███████║
╚═╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚═════╝ ╚═════╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚══════╝
```

20
poetry.lock generated
View File

@ -11,24 +11,6 @@ files = [
{file = "annotated_types-0.6.0.tar.gz", hash = "sha256:563339e807e53ffd9c267e99fc6d9ea23eb8443c08f112651963e24e22f84a5d"}, {file = "annotated_types-0.6.0.tar.gz", hash = "sha256:563339e807e53ffd9c267e99fc6d9ea23eb8443c08f112651963e24e22f84a5d"},
] ]
[[package]]
name = "factory-boy"
version = "3.3.0"
description = "A versatile test fixtures replacement based on thoughtbot's factory_bot for Ruby."
optional = false
python-versions = ">=3.7"
files = [
{file = "factory_boy-3.3.0-py2.py3-none-any.whl", hash = "sha256:a2cdbdb63228177aa4f1c52f4b6d83fab2b8623bf602c7dedd7eb83c0f69c04c"},
{file = "factory_boy-3.3.0.tar.gz", hash = "sha256:bc76d97d1a65bbd9842a6d722882098eb549ec8ee1081f9fb2e8ff29f0c300f1"},
]
[package.dependencies]
Faker = ">=0.7.0"
[package.extras]
dev = ["Django", "Pillow", "SQLAlchemy", "coverage", "flake8", "isort", "mongoengine", "sqlalchemy-utils", "tox", "wheel (>=0.32.0)", "zest.releaser[recommended]"]
doc = ["Sphinx", "sphinx-rtd-theme", "sphinxcontrib-spelling"]
[[package]] [[package]]
name = "faker" name = "faker"
version = "19.9.0" version = "19.9.0"
@ -295,4 +277,4 @@ files = [
[metadata] [metadata]
lock-version = "2.0" lock-version = "2.0"
python-versions = "^3.11" python-versions = "^3.11"
content-hash = "c2ab39cad71a6932e73868eb4f8513ca8fcf3c01d5337bf463607f9a1ab7be06" content-hash = "f67f7e3c078da6291615ead8743e8eb520d31e62bab449b5cd5f3e9b3b3f540e"

View File

@ -10,7 +10,6 @@ packages = [{include = "pydantic_vs_msgspec"}]
python = "^3.11" python = "^3.11"
pydantic = "^2.4.2" pydantic = "^2.4.2"
msgspec = "^0.18.4" msgspec = "^0.18.4"
factory-boy = "^3.3.0"
polyfactory = "^2.9.0" polyfactory = "^2.9.0"