Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ jobs:
uses: CodSpeedHQ/action@346a2d8a8d9d38909abd0bc3d23f773110f076ad # v4.4.1
with:
mode: simulation
run: uv run --with pytest-codspeed --with pytest-benchmark pytest --codspeed bench/
run: uv run --with pytest-codspeed --with pytest-benchmark --group test --extra msgspec --extra orjson pytest --codspeed bench/
4 changes: 2 additions & 2 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ covall:
@rm .coverage*

bench-cmp:
uv run pytest bench --benchmark-compare
uv run --group test pytest bench --benchmark-compare

bench:
uv run pytest bench --benchmark-save base
uv run --group test pytest bench --benchmark-save base

docs output_dir="_build": ## generate Sphinx HTML documentation, including API docs
make -C docs -e BUILDDIR={{output_dir}} clean
Expand Down
80 changes: 40 additions & 40 deletions bench/test_attrs_collections.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from enum import IntEnum
from typing import Dict, List, Mapping, MutableMapping
from typing import Mapping, MutableMapping

import attr
import pytest
from attrs import define, frozen

from cattr import BaseConverter, Converter, UnstructureStrategy
from cattrs import BaseConverter, Converter, UnstructureStrategy


@pytest.mark.parametrize("converter_cls", [BaseConverter, Converter])
Expand All @@ -21,38 +21,38 @@ class E(IntEnum):
ONE = 1
TWO = 2

@attr.define
@define
class C:
a: List[int]
b: List[float]
c: List[str]
d: List[bytes]
e: List[E]
f: List[int]
g: List[float]
h: List[str]
i: List[bytes]
j: List[E]
k: List[int]
l: List[float] # noqa: E741
m: List[str]
n: List[bytes]
o: List[E]
p: List[int]
q: List[float]
r: List[str]
s: List[bytes]
t: List[E]
u: List[int]
v: List[float]
w: List[str]
x: List[bytes]
y: List[E]
z: List[int]
aa: List[float]
ab: List[str]
ac: List[bytes]
ad: List[E]
a: list[int]
b: list[float]
c: list[str]
d: list[bytes]
e: list[E]
f: list[int]
g: list[float]
h: list[str]
i: list[bytes]
j: list[E]
k: list[int]
l: list[float] # noqa: E741
m: list[str]
n: list[bytes]
o: list[E]
p: list[int]
q: list[float]
r: list[str]
s: list[bytes]
t: list[E]
u: list[int]
v: list[float]
w: list[str]
x: list[bytes]
y: list[E]
z: list[int]
aa: list[float]
ab: list[str]
ac: list[bytes]
ad: list[E]

c = converter_cls(unstruct_strat=unstructure_strat)

Expand Down Expand Up @@ -102,14 +102,14 @@ def test_unstructure_attrs_mappings(benchmark, converter_cls, unstructure_strat)
Benchmark an attrs class containing mappings.
"""

@attr.frozen
@frozen
class FrozenCls:
a: int

@attr.define
@define
class C:
a: Mapping[int, str]
b: Dict[float, bytes]
b: dict[float, bytes]
c: MutableMapping[int, FrozenCls]

c = converter_cls(unstruct_strat=unstructure_strat)
Expand All @@ -130,14 +130,14 @@ def test_structure_attrs_mappings(benchmark, converter_cls):
Benchmark an attrs class containing mappings.
"""

@attr.frozen
@frozen
class FrozenCls:
a: int

@attr.define
@define
class C:
a: Mapping[int, str]
b: Dict[float, bytes]
b: dict[float, bytes]
c: MutableMapping[int, FrozenCls]

c = converter_cls()
Expand Down
2 changes: 1 addition & 1 deletion bench/test_attrs_nested.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
from attrs import define

from cattr import BaseConverter, Converter, UnstructureStrategy
from cattrs import BaseConverter, Converter, UnstructureStrategy


@pytest.mark.parametrize("converter_cls", [BaseConverter, Converter])
Expand Down
6 changes: 3 additions & 3 deletions bench/test_attrs_primitives.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from enum import IntEnum

import attr
import pytest
from attrs import define

from cattr import BaseConverter, Converter, UnstructureStrategy
from cattrs import BaseConverter, Converter, UnstructureStrategy


class E(IntEnum):
ONE = 1
TWO = 2


@attr.define
@define
class C:
a: int
b: float
Expand Down
68 changes: 68 additions & 0 deletions bench/test_enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from enum import Enum, IntEnum, StrEnum

import pytest

from cattrs import BaseConverter, Converter
from cattrs.preconf.msgspec import MsgspecJsonConverter
from cattrs.preconf.orjson import OrjsonConverter


class SimpleEnum(Enum):
FIRST = "first"
SECOND = "second"
THIRD = "third"


class SimpleIntEnum(IntEnum):
ONE = 1
TWO = 2
THREE = 3


class SimpleStrEnum(StrEnum):
ALPHA = "alpha"
BETA = "beta"
GAMMA = "gamma"


@pytest.mark.parametrize("converter_cls", [BaseConverter, Converter, MsgspecJsonConverter, OrjsonConverter])
def test_unstructure_simple_enum(benchmark, converter_cls):
"""Benchmark unstructuring a simple enum."""
c = converter_cls()
benchmark(c.unstructure, SimpleEnum.FIRST)


@pytest.mark.parametrize("converter_cls", [BaseConverter, Converter, MsgspecJsonConverter, OrjsonConverter])
def test_structure_simple_enum(benchmark, converter_cls):
"""Benchmark structuring a simple enum."""
c = converter_cls()
benchmark(c.structure, "first", SimpleEnum)


@pytest.mark.parametrize("converter_cls", [BaseConverter, Converter, MsgspecJsonConverter, OrjsonConverter])
def test_unstructure_simple_int_enum(benchmark, converter_cls):
"""Benchmark unstructuring a simple IntEnum."""
c = converter_cls()
benchmark(c.unstructure, SimpleIntEnum.ONE)


@pytest.mark.parametrize("converter_cls", [BaseConverter, Converter, MsgspecJsonConverter, OrjsonConverter])
def test_structure_simple_int_enum(benchmark, converter_cls):
"""Benchmark structuring a simple IntEnum."""
c = converter_cls()
benchmark(c.structure, 1, SimpleIntEnum)


@pytest.mark.parametrize("converter_cls", [BaseConverter, Converter, MsgspecJsonConverter, OrjsonConverter])
def test_unstructure_simple_str_enum(benchmark, converter_cls):
"""Benchmark unstructuring a simple StrEnum."""
c = converter_cls()
benchmark(c.unstructure, SimpleStrEnum.ALPHA)


@pytest.mark.parametrize("converter_cls", [BaseConverter, Converter, MsgspecJsonConverter, OrjsonConverter])
def test_structure_simple_str_enum(benchmark, converter_cls):
"""Benchmark structuring a simple StrEnum."""
c = converter_cls()
benchmark(c.structure, "alpha", SimpleStrEnum)

2 changes: 1 addition & 1 deletion bench/test_primitives.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from cattr import BaseConverter, Converter
from cattrs import BaseConverter, Converter


@pytest.mark.parametrize("converter_cls", [BaseConverter, Converter])
Expand Down
Loading