Skip to content

Commit e7b77ca

Browse files
authored
Make benchmarks stable, the second attempt (#1206)
Problematic benchmarks now ask not the single key, but three sibling keys. These keys have different hashes, maybe it could help with amortizing benchmark time after hash collisions. See #1201 for details
1 parent 06f1301 commit e7b77ca

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

tests/test_multidict_benchmarks.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ def test_multidict_getall_str_hit(
262262
@benchmark
263263
def _run() -> None:
264264
for i in range(30):
265+
md.getall("key1")
266+
md.getall("key2")
265267
md.getall("key3")
266268

267269

@@ -275,37 +277,41 @@ def test_multidict_getall_str_miss(
275277
@benchmark
276278
def _run() -> None:
277279
for i in range(30):
278-
md.getall("miss", ())
280+
md.getall("miss1", ())
281+
md.getall("miss2", ())
282+
md.getall("miss3", ())
279283

280284

281285
def test_cimultidict_getall_istr_hit(
282286
benchmark: BenchmarkFixture,
283287
case_insensitive_multidict_class: Type[CIMultiDict[istr]],
284288
) -> None:
285-
all_istr = istr("key3")
289+
all_istr = [istr("key1"), istr("key2"), istr("key3")]
286290
md = case_insensitive_multidict_class(
287291
(f"key{j}", istr(f"{i}-{j}")) for i in range(20) for j in range(5)
288292
)
289293

290294
@benchmark
291295
def _run() -> None:
292296
for i in range(30):
293-
md.getall(all_istr)
297+
for key in all_istr:
298+
md.getall(key)
294299

295300

296301
def test_cimultidict_getall_istr_miss(
297302
benchmark: BenchmarkFixture,
298303
case_insensitive_multidict_class: Type[CIMultiDict[istr]],
299304
) -> None:
300-
miss_istr = istr("miss")
305+
miss_istr = [istr("miss-1"), istr("miss-2"), istr("miss-3")]
301306
md = case_insensitive_multidict_class(
302307
(istr(f"key{j}"), istr(f"{i}-{j}")) for i in range(20) for j in range(5)
303308
)
304309

305310
@benchmark
306311
def _run() -> None:
307312
for i in range(30):
308-
md.getall(miss_istr, ())
313+
for key in miss_istr:
314+
md.getall(key, ())
309315

310316

311317
def test_multidict_fetch(

0 commit comments

Comments
 (0)