Skip to content

Commit

Permalink
Add benchmark for subtracting long URL paths (#1387)
Browse files Browse the repository at this point in the history
The performance is currently nearly quadratic so its
good to compare a short and long url
  • Loading branch information
bdraco authored Oct 24, 2024
1 parent cb550b7 commit 7a272d2
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/test_url_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
SIMPLE_QUERY = {str(i): str(i) for i in range(10)}
SIMPLE_INT_QUERY = {str(i): i for i in range(10)}
QUERY_STRING = "x=y&z=1"
URL_VERY_LONG_PATH = URL("http://www.domain.tld/" + "req/" * 100)
URL_LONG_PATH = URL("http://www.domain.tld/" + "req/" * 30)


class _SubClassedStr(str):
Expand Down Expand Up @@ -594,6 +596,13 @@ def _run() -> None:
URL_WITH_LONGER_PATH - URL_WITH_PATH


def test_url_subtract_long_urls(benchmark: BenchmarkFixture) -> None:
@benchmark
def _run() -> None:
for _ in range(100):
URL_VERY_LONG_PATH - URL_LONG_PATH


def test_url_host_port_subcomponent(benchmark: BenchmarkFixture) -> None:
cache_non_default = URL_WITH_NOT_DEFAULT_PORT._cache
cache = BASE_URL._cache
Expand Down

0 comments on commit 7a272d2

Please sign in to comment.