diff --git a/benchmark/charts/dump_dark.svg b/benchmark/charts/dump_dark.svg index f32436f3..08b64d1c 100644 --- a/benchmark/charts/dump_dark.svg +++ b/benchmark/charts/dump_dark.svg @@ -1 +1 @@ -1 us10 us100 us1000 usmashumarocattrspydantic v2asdictmarshmallowpydantic v1dataclasses-json12.4 us18.0 us118 us122 us124 us556 us6.74 usConverting GitHub Issue object to dict +1 us10 us100 us1000 usmashumarocattrspydantic v2asdictmarshmallowpydantic v1dataclasses-json9.74 us18.4 us46.3 us141 us155 us642 us7.66 usConverting GitHub Issue object to dict \ No newline at end of file diff --git a/benchmark/charts/dump_light.svg b/benchmark/charts/dump_light.svg index 70124a85..aacdd916 100644 --- a/benchmark/charts/dump_light.svg +++ b/benchmark/charts/dump_light.svg @@ -1 +1 @@ -1 us10 us100 us1000 usmashumarocattrspydantic v2asdictmarshmallowpydantic v1dataclasses-json12.4 us18.0 us118 us122 us124 us556 us6.74 usConverting GitHub Issue object to dict +1 us10 us100 us1000 usmashumarocattrspydantic v2asdictmarshmallowpydantic v1dataclasses-json9.74 us18.4 us46.3 us141 us155 us642 us7.66 usConverting GitHub Issue object to dict \ No newline at end of file diff --git a/benchmark/charts/load_dark.svg b/benchmark/charts/load_dark.svg index b2d47918..7bc417ce 100644 --- a/benchmark/charts/load_dark.svg +++ b/benchmark/charts/load_dark.svg @@ -1 +1 @@ -10 us100 us1000 us10000 usmashumarocattrspydantic v2pydantic v1marshmallowdataclasses-jsondacite17.7 us19.9 us114 us281 us1.05 ms1.66 ms14.1 usCreating GitHub Issue object from dict +10 us100 us1000 us10000 usmashumarocattrspydantic v2pydantic v1marshmallowdataclasses-jsondacite16.1 us19.2 us128 us322 us1.17 ms1.30 ms12.4 usCreating GitHub Issue object from dict \ No newline at end of file diff --git a/benchmark/charts/load_light.svg b/benchmark/charts/load_light.svg index f05b826d..668f5dc9 100644 --- a/benchmark/charts/load_light.svg +++ b/benchmark/charts/load_light.svg @@ -1 +1 @@ -10 us100 us1000 us10000 usmashumarocattrspydantic v2pydantic v1marshmallowdataclasses-jsondacite17.7 us19.9 us114 us281 us1.05 ms1.66 ms14.1 usCreating GitHub Issue object from dict +10 us100 us1000 us10000 usmashumarocattrspydantic v2pydantic v1marshmallowdataclasses-jsondacite16.1 us19.2 us128 us322 us1.17 ms1.30 ms12.4 usCreating GitHub Issue object from dict \ No newline at end of file diff --git a/benchmark/common.py b/benchmark/common.py index 24329007..7a5182a8 100644 --- a/benchmark/common.py +++ b/benchmark/common.py @@ -1,9 +1,7 @@ -import argparse -import gc import json import pathlib -from abc import ABC, abstractmethod -from typing import Any, Dict, List, Literal, Type +from abc import ABC +from typing import Any, Dict, Literal, Type import pyperf diff --git a/benchmark/libs/asdict/common.py b/benchmark/libs/asdict/common.py index 290ab46a..cce16c5f 100644 --- a/benchmark/libs/asdict/common.py +++ b/benchmark/libs/asdict/common.py @@ -3,15 +3,19 @@ import pyperf from benchmark.common import AbstractBenchmark -from benchmark.libs.mashumaro.common import Issue +from benchmark.libs.mashumaro.common import BasicDecoder, DefaultDialect, Issue class Benchmark(AbstractBenchmark): LIBRARY = "asdict" + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.decoder = BasicDecoder(Issue, default_dialect=DefaultDialect) + def warmup(self, data) -> None: - asdict(Issue.from_dict(data)) + asdict(self.decoder.decode(data)) def run_dumper(self, data) -> pyperf.Benchmark: - obj = Issue.from_dict(data) + obj = self.decoder.decode(data) return self._bench_dumper_func(asdict, obj) diff --git a/benchmark/libs/mashumaro/common.py b/benchmark/libs/mashumaro/common.py index b7782788..f502d69c 100644 --- a/benchmark/libs/mashumaro/common.py +++ b/benchmark/libs/mashumaro/common.py @@ -6,18 +6,17 @@ import pyperf from benchmark.common import AbstractBenchmark -from mashumaro import DataClassDictMixin, field_options, pass_through -from mashumaro.config import BaseConfig +from mashumaro import field_options, pass_through +from mashumaro.codecs import BasicDecoder, BasicEncoder +from mashumaro.dialect import Dialect -class BaseModel(DataClassDictMixin): - class Config(BaseConfig): - lazy_compilation = True - serialize_by_alias = True - serialization_strategy = { - str: {"deserialize": str, "serialize": pass_through}, - int: {"serialize": pass_through}, - } +class DefaultDialect(Dialect): + serialize_by_alias = True + serialization_strategy = { + str: {"deserialize": str, "serialize": pass_through}, + int: {"serialize": pass_through}, + } class IssueState(Enum): @@ -48,7 +47,7 @@ class AuthorAssociation(Enum): @dataclass(slots=True) -class User(BaseModel): +class User: login: str id: int node_id: str @@ -73,7 +72,7 @@ class User(BaseModel): @dataclass(slots=True) -class IssueLabel(BaseModel): +class IssueLabel: id: int node_id: str url: str @@ -84,7 +83,7 @@ class IssueLabel(BaseModel): @dataclass(slots=True) -class Milestone(BaseModel): +class Milestone: url: str html_url: str labels_url: str @@ -104,7 +103,7 @@ class Milestone(BaseModel): @dataclass(slots=True) -class Reactions(BaseModel): +class Reactions: url: str total_count: int plus_one: int = field(metadata=field_options(alias="+1")) @@ -118,7 +117,7 @@ class Reactions(BaseModel): @dataclass(slots=True) -class Issue(BaseModel): +class Issue: id: int node_id: str url: str @@ -155,12 +154,17 @@ class Issue(BaseModel): class Benchmark(AbstractBenchmark): LIBRARY = "mashumaro" + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.decoder = BasicDecoder(Issue, default_dialect=DefaultDialect) + self.encoder = BasicEncoder(Issue, default_dialect=DefaultDialect) + def warmup(self, data) -> None: - Issue.from_dict(data).to_dict() + self.encoder.encode(self.decoder.decode(data)) def run_loader(self, data) -> pyperf.Benchmark: - return self._bench_loader_func(Issue.from_dict, data) + return self._bench_loader_func(self.decoder.decode, data) def run_dumper(self, data) -> pyperf.Benchmark: - obj = Issue.from_dict(data) - return self._bench_dumper_func(obj.to_dict) + obj = self.decoder.decode(data) + return self._bench_dumper_func(self.encoder.encode, obj) diff --git a/requirements-dev.txt b/requirements-dev.txt index f0d1d1a9..1c643fe1 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -24,11 +24,11 @@ pendulum>=2.1.2;python_version<'3.12' pyperf>=2.6.1 termtables>=0.2.3 pytablewriter[html]>=0.58.0 -cattrs==23.1.2 -pydantic==2.1.1 +cattrs==23.2.2 +pydantic==2.5.1 dacite==1.7.0 # see https://github.com/konradhalas/dacite/issues/236#issuecomment-1613987368 marshmallow>=3.19.0 -dataclasses-json==0.5.14 +dataclasses-json==0.6.2 # library stubs types-backports