Skip to content

Commit

Permalink
Update benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Fatal1ty committed Nov 23, 2023
1 parent d526eb4 commit d5f98a2
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 33 deletions.
2 changes: 1 addition & 1 deletion benchmark/charts/dump_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion benchmark/charts/dump_light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion benchmark/charts/load_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion benchmark/charts/load_light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 2 additions & 4 deletions benchmark/common.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
10 changes: 7 additions & 3 deletions benchmark/libs/asdict/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
42 changes: 23 additions & 19 deletions benchmark/libs/mashumaro/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -48,7 +47,7 @@ class AuthorAssociation(Enum):


@dataclass(slots=True)
class User(BaseModel):
class User:
login: str
id: int
node_id: str
Expand All @@ -73,7 +72,7 @@ class User(BaseModel):


@dataclass(slots=True)
class IssueLabel(BaseModel):
class IssueLabel:
id: int
node_id: str
url: str
Expand All @@ -84,7 +83,7 @@ class IssueLabel(BaseModel):


@dataclass(slots=True)
class Milestone(BaseModel):
class Milestone:
url: str
html_url: str
labels_url: str
Expand All @@ -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"))
Expand All @@ -118,7 +117,7 @@ class Reactions(BaseModel):


@dataclass(slots=True)
class Issue(BaseModel):
class Issue:
id: int
node_id: str
url: str
Expand Down Expand Up @@ -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)
6 changes: 3 additions & 3 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d5f98a2

Please sign in to comment.