Skip to content

Commit 6474469

Browse files
perf(benchmarks): add ttl_cache microbench (#238)
Summary - Add a ttl_cache microbenchmark to track cached call overhead with a frozen timer. Rationale - Freezing the cache timer keeps the benchmark in the cache-hit path even on slower CI, yielding stable results. Details - New `benchmarks/test_cache_benchmarks.py` adds a ttl_cache microbench using a frozen timer function. - Tests: `python setup.py build_ext --inplace` (mypy-compiled extensions; verified `evmspec/_new.cpython-314-x86_64-linux-gnu.so`), `python -m pytest benchmarks/`.
1 parent e540176 commit 6474469

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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.data._cache import ttl_cache
7+
8+
9+
def _frozen_time() -> float:
10+
return 0.0
11+
12+
13+
@pytest.mark.benchmark(group="ttl_cache_call")
14+
def test_ttl_cache_call(benchmark: BenchmarkFixture) -> None:
15+
@ttl_cache(maxsize=32, ttl=1, timer=_frozen_time)
16+
def _cached_call(x: int) -> int:
17+
return x + 1
18+
19+
benchmark(batch, 25_000, _cached_call, 1)

0 commit comments

Comments
 (0)