Skip to content

Commit ad678ff

Browse files
test(benchmarks): cover all uint types (#235)
Summary - add constructor benchmarks for every uint width discovered from `evmspec.data.uints` - exercise both zero and max values per type to cover edge-case boundaries Rationale - ensure microbenchmarks cover all uint types to spot performance regressions or discrepancies across widths Details - builds the param matrix dynamically from `uint<N>` classes and uses HexBytes zero/max inputs - tests: `PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 PYTHONPATH=/home/takopi/projects/evmspec/build/lib.linux-x86_64-cpython-313:/home/takopi/projects/evmspec /home/takopi/projects/evmspec/.venv/bin/pytest -p pytest_codspeed.plugin /home/takopi/projects/evmspec/benchmarks/test_uints_benchmarks.py --codspeed` - mypyc check: `PYTHONPATH=/home/takopi/projects/evmspec/build/lib.linux-x86_64-cpython-313:/home/takopi/projects/evmspec /home/takopi/projects/evmspec/.venv/bin/python -c "import evmspec._new as m; print(m.__file__)"` -> `.../build/lib.linux-x86_64-cpython-313/evmspec/_new.cpython-313-x86_64-linux-gnu.so`
1 parent 5c477d5 commit ad678ff

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# mypy: disable-error-code=misc
2+
import pytest
3+
from hexbytes import HexBytes
4+
from pytest_codspeed import BenchmarkFixture
5+
6+
from benchmarks.batch import batch
7+
from evmspec.data import uints
8+
9+
10+
def _collect_uint_classes() -> list[type]:
11+
# Discover all uint<N> classes, including dynamically generated ones.
12+
classes: list[tuple[int, type]] = []
13+
for name in dir(uints):
14+
if not name.startswith("uint"):
15+
continue
16+
suffix = name[4:]
17+
if not suffix.isdigit():
18+
continue
19+
cls = getattr(uints, name)
20+
if isinstance(cls, type):
21+
classes.append((int(suffix), cls))
22+
classes.sort(key=lambda item: item[0])
23+
return [cls for _, cls in classes]
24+
25+
26+
UINT_CLASSES = _collect_uint_classes()
27+
ZERO_VALUE = HexBytes("0x")
28+
29+
UINT_CASES = []
30+
for cls in UINT_CLASSES:
31+
max_value = HexBytes("0x" + "ff" * cls.bytes)
32+
UINT_CASES.append((cls, ZERO_VALUE, f"{cls.__name__}-zero"))
33+
UINT_CASES.append((cls, max_value, f"{cls.__name__}-max"))
34+
35+
UINT_CASE_VALUES = [(cls, value) for cls, value, _ in UINT_CASES]
36+
UINT_CASE_IDS = [case_id for _, _, case_id in UINT_CASES]
37+
38+
39+
@pytest.mark.benchmark(group="uints_construct")
40+
@pytest.mark.parametrize("cls, value", UINT_CASE_VALUES, ids=UINT_CASE_IDS)
41+
def test_uints_construct(benchmark: BenchmarkFixture, cls, value) -> None:
42+
benchmark(batch, 20_000, cls, value)

0 commit comments

Comments
 (0)