Skip to content

Commit 7585a96

Browse files
authored
Add benchmarks that bypass the cached property decorators (#1445)
1 parent aecebb1 commit 7585a96

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

tests/test_url_benchmarks.py

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,15 @@ def _run() -> None:
584584
url.query_string
585585

586586

587+
def test_empty_query_string_uncached(benchmark: BenchmarkFixture) -> None:
588+
urls = [URL(BASE_URL_STR) for _ in range(100)]
589+
590+
@benchmark
591+
def _run() -> None:
592+
for url in urls:
593+
URL.query_string.wrapped(url)
594+
595+
587596
def test_query(benchmark: BenchmarkFixture) -> None:
588597
urls = [URL(QUERY_URL_STR) for _ in range(100)]
589598

@@ -613,3 +622,111 @@ def _run() -> None:
613622
cache_non_default.pop("host_port_subcomponent", None)
614623
URL_WITH_NOT_DEFAULT_PORT.host_port_subcomponent
615624
BASE_URL.host_port_subcomponent
625+
626+
627+
def test_empty_path(benchmark: BenchmarkFixture) -> None:
628+
"""Test accessing empty path."""
629+
630+
@benchmark
631+
def _run() -> None:
632+
for _ in range(100):
633+
BASE_URL.path
634+
635+
636+
def test_empty_path_uncached(benchmark: BenchmarkFixture) -> None:
637+
"""Test accessing empty path without cache."""
638+
639+
@benchmark
640+
def _run() -> None:
641+
for _ in range(100):
642+
URL.path.wrapped(BASE_URL)
643+
644+
645+
def test_empty_path_safe(benchmark: BenchmarkFixture) -> None:
646+
"""Test accessing empty path safe."""
647+
648+
@benchmark
649+
def _run() -> None:
650+
for _ in range(100):
651+
BASE_URL.path_safe
652+
653+
654+
def test_empty_path_safe_uncached(benchmark: BenchmarkFixture) -> None:
655+
"""Test accessing empty path safe without cache."""
656+
657+
@benchmark
658+
def _run() -> None:
659+
for _ in range(100):
660+
URL.path_safe.wrapped(BASE_URL)
661+
662+
663+
def test_path_safe(benchmark: BenchmarkFixture) -> None:
664+
"""Test accessing path safe."""
665+
666+
@benchmark
667+
def _run() -> None:
668+
for _ in range(100):
669+
URL_WITH_PATH.path_safe
670+
671+
672+
def test_path_safe_uncached(benchmark: BenchmarkFixture) -> None:
673+
"""Test accessing path safe without cache."""
674+
675+
@benchmark
676+
def _run() -> None:
677+
for _ in range(100):
678+
URL.path_safe.wrapped(URL_WITH_PATH)
679+
680+
681+
def test_empty_raw_path_qs(benchmark: BenchmarkFixture) -> None:
682+
"""Test accessing empty raw path with query."""
683+
684+
@benchmark
685+
def _run() -> None:
686+
for _ in range(100):
687+
BASE_URL.raw_path_qs
688+
689+
690+
def test_empty_raw_path_qs_uncached(benchmark: BenchmarkFixture) -> None:
691+
"""Test accessing empty raw path with query without cache."""
692+
693+
@benchmark
694+
def _run() -> None:
695+
for _ in range(100):
696+
URL.raw_path_qs.wrapped(BASE_URL)
697+
698+
699+
def test_raw_path_qs(benchmark: BenchmarkFixture) -> None:
700+
"""Test accessing raw path qs without query."""
701+
702+
@benchmark
703+
def _run() -> None:
704+
for _ in range(100):
705+
URL_WITH_PATH.raw_path_qs
706+
707+
708+
def test_raw_path_qs_uncached(benchmark: BenchmarkFixture) -> None:
709+
"""Test accessing raw path qs without query and without cache."""
710+
711+
@benchmark
712+
def _run() -> None:
713+
for _ in range(100):
714+
URL.raw_path_qs.wrapped(URL_WITH_PATH)
715+
716+
717+
def test_raw_path_qs_with_query(benchmark: BenchmarkFixture) -> None:
718+
"""Test accessing raw path qs with query."""
719+
720+
@benchmark
721+
def _run() -> None:
722+
for _ in range(100):
723+
IPV6_QUERY_URL.raw_path_qs
724+
725+
726+
def test_raw_path_qs_with_query_uncached(benchmark: BenchmarkFixture) -> None:
727+
"""Test accessing raw path qs with query and without cache."""
728+
729+
@benchmark
730+
def _run() -> None:
731+
for _ in range(100):
732+
URL.raw_path_qs.wrapped(IPV6_QUERY_URL)

0 commit comments

Comments
 (0)