Skip to content

Commit 35e970c

Browse files
test(benchmarks): parametrize enum microbench inputs (#232)
## Summary - add enum benchmark suite for call/reward types - parametrize call/reward enums over string, int, and enum-member inputs - keep status enum benchmark coverage intact ## Rationale We want more robust microbench coverage for enum coercion paths so regressions in string/int/member handling are visible. ## Details - Ran `PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 .venv/bin/pytest -p pytest_codspeed.plugin benchmarks/ --codspeed` (36 passed). - Confirmed mypyc extensions were used by importing from `/tmp` with `.venv/bin/python` and verifying `evmspec__mypyc.cpython-313-x86_64-linux-gnu.so` + `evmspec/_new.cpython-313-x86_64-linux-gnu.so` in site-packages.
1 parent 8205377 commit 35e970c

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

benchmarks/test_enum_benchmarks.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# mypy: disable-error-code=misc
2+
import pytest
3+
from pytest_codspeed import BenchmarkFixture
4+
5+
from benchmarks.batch import batch
6+
from evmspec.structs.receipt import Status
7+
from evmspec.structs.trace import call, reward
8+
9+
TRACE_TYPE_CASES = [
10+
(call.Type, "call", "call-str-call"),
11+
(call.Type, "delegatecall", "call-str-delegatecall"),
12+
(call.Type, "staticcall", "call-str-staticcall"),
13+
(call.Type, 0, "call-int-call"),
14+
(call.Type, 1, "call-int-delegatecall"),
15+
(call.Type, 2, "call-int-staticcall"),
16+
(call.Type, call.Type.call, "call-enum-call"),
17+
(call.Type, call.Type.delegatecall, "call-enum-delegatecall"),
18+
(call.Type, call.Type.staticcall, "call-enum-staticcall"),
19+
(reward.Type, "block", "reward-str-block"),
20+
(reward.Type, "uncle", "reward-str-uncle"),
21+
(reward.Type, 0, "reward-int-block"),
22+
(reward.Type, 1, "reward-int-uncle"),
23+
(reward.Type, reward.Type.block, "reward-enum-block"),
24+
(reward.Type, reward.Type.uncle, "reward-enum-uncle"),
25+
]
26+
TRACE_TYPE_VALUES = [(enum_cls, value) for enum_cls, value, _ in TRACE_TYPE_CASES]
27+
TRACE_TYPE_IDS = [case_id for _, _, case_id in TRACE_TYPE_CASES]
28+
STATUS_CASES = [
29+
("0x1", "hex-success"),
30+
("0x0", "hex-failure"),
31+
("1", "dec-success"),
32+
("0", "dec-failure"),
33+
("0X1", "hex-upper-success"),
34+
("0X0", "hex-upper-failure"),
35+
]
36+
STATUS_VALUES = [value for value, _ in STATUS_CASES]
37+
STATUS_IDS = [case_id for _, case_id in STATUS_CASES]
38+
39+
40+
@pytest.mark.benchmark(group="trace_type_enum")
41+
@pytest.mark.parametrize("enum_cls, value", TRACE_TYPE_VALUES, ids=TRACE_TYPE_IDS)
42+
def test_trace_type_enum(benchmark: BenchmarkFixture, enum_cls, value) -> None:
43+
benchmark(batch, 20_000, enum_cls, value)
44+
45+
46+
@pytest.mark.benchmark(group="status_enum")
47+
@pytest.mark.parametrize("value", STATUS_VALUES, ids=STATUS_IDS)
48+
def test_status_enum(benchmark: BenchmarkFixture, value) -> None:
49+
benchmark(batch, 20_000, Status, value)

0 commit comments

Comments
 (0)