-
Notifications
You must be signed in to change notification settings - Fork 227
Expand file tree
/
Copy pathtest_mark_seen.py
More file actions
39 lines (27 loc) · 1.08 KB
/
test_mark_seen.py
File metadata and controls
39 lines (27 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""Benchmark for _logger._mark_seen."""
from __future__ import annotations
from pytest_codspeed import BenchmarkFixture
from zeroconf._logger import _MAX_SEEN_LOGS, _mark_seen
def test_mark_seen_hit(benchmark: BenchmarkFixture) -> None:
"""Benchmark the cache-hit path (same key repeated)."""
seen: dict[str, None] = {"warm": None}
@benchmark
def _hit() -> None:
for _ in range(1000):
_mark_seen(seen, "warm")
def test_mark_seen_fill(benchmark: BenchmarkFixture) -> None:
"""Benchmark filling from empty up to the cap (no evictions)."""
keys = [f"key-{i}" for i in range(_MAX_SEEN_LOGS)]
@benchmark
def _fill() -> None:
seen: dict[str, None] = {}
for k in keys:
_mark_seen(seen, k)
def test_mark_seen_churn(benchmark: BenchmarkFixture) -> None:
"""Benchmark sustained eviction (every call past the cap drops oldest)."""
keys = [f"churn-{i}" for i in range(_MAX_SEEN_LOGS * 4)]
@benchmark
def _churn() -> None:
seen: dict[str, None] = {}
for k in keys:
_mark_seen(seen, k)