Skip to content
Merged
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
53 changes: 53 additions & 0 deletions bench/test_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,56 @@ def test_hash():

for _ in range(ROUNDS):
hash(c)


def test_asdict_complicated():
"""
Benchmark instances with non-shortcut fields.
"""
c = C()
ad = attrs.asdict

for _ in range(ROUNDS):
ad(c)


def test_astuple_complicated():
"""
Benchmark instances with non-shortcut fields.
"""
c = C()
at = attrs.astuple

for _ in range(ROUNDS):
at(c)


@attrs.define
class AtomicFields:
a: int = 0
b: Ellipsis = ...
c: str = "foo"
d: tuple[str] = "bar"
e: complex = complex()


def test_asdict_atomic():
"""
Benchmark atomic-only instances.
"""
c = AtomicFields()
ad = attrs.asdict

for _ in range(ROUNDS):
ad(c)


def test_astuple_atomic():
"""
Benchmark atomic-only instances.
"""
c = AtomicFields()
at = attrs.astuple

for _ in range(ROUNDS):
at(c)