Skip to content

Commit b5d9bd1

Browse files
authored
Add benchmarks for iterating multidict (#1107)
1 parent 1ba64e7 commit b5d9bd1

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

tests/test_multidict_benchmarks.py

+46
Original file line numberDiff line numberDiff line change
@@ -552,3 +552,49 @@ def test_copy_from_existing_cimultidict(
552552
@benchmark
553553
def _run() -> None:
554554
existing.copy()
555+
556+
557+
def test_iterate_multidict(
558+
benchmark: BenchmarkFixture, any_multidict_class: Type[MultiDict[str]]
559+
) -> None:
560+
items = [(str(i), str(i)) for i in range(100)]
561+
md = any_multidict_class(items)
562+
563+
@benchmark
564+
def _run() -> None:
565+
for _ in md:
566+
pass
567+
568+
def test_iterate_multidict_keys(
569+
benchmark: BenchmarkFixture, any_multidict_class: Type[MultiDict[str]]
570+
) -> None:
571+
items = [(str(i), str(i)) for i in range(100)]
572+
md = any_multidict_class(items)
573+
574+
@benchmark
575+
def _run() -> None:
576+
for _ in md.keys():
577+
pass
578+
579+
580+
def test_iterate_multidict_values(
581+
benchmark: BenchmarkFixture, any_multidict_class: Type[MultiDict[str]]
582+
) -> None:
583+
items = [(str(i), str(i)) for i in range(100)]
584+
md = any_multidict_class(items)
585+
586+
@benchmark
587+
def _run() -> None:
588+
for _ in md.values():
589+
pass
590+
591+
def test_iterate_multidict_items(
592+
benchmark: BenchmarkFixture, any_multidict_class: Type[MultiDict[str]]
593+
) -> None:
594+
items = [(str(i), str(i)) for i in range(100)]
595+
md = any_multidict_class(items)
596+
597+
@benchmark
598+
def _run() -> None:
599+
for _, _ in md.items():
600+
pass

0 commit comments

Comments
 (0)