Skip to content

Commit

Permalink
Fix query benchmarks to avoid testing property cache hits (#1300)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Oct 16, 2024
1 parent cd1d352 commit 6e574b6
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions tests/test_url_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

MANY_HOSTS = [f"www.domain{i}.tld" for i in range(256)]
MANY_URLS = [f"https://www.domain{i}.tld" for i in range(256)]
BASE_URL = URL("http://www.domain.tld")
BASE_URL_STR = "http://www.domain.tld"
BASE_URL = URL(BASE_URL_STR)
URL_WITH_USER_PASS = URL("http://user:[email protected]")
IPV6_QUERY_URL = URL("http://[::1]/req?query=1&query=2&query=3&query=4&query=5")
URL_WITH_NOT_DEFAULT_PORT = URL("http://www.domain.tld:1234")
QUERY_URL = URL("http://www.domain.tld?query=1&query=2&query=3&query=4&query=5")
QUERY_URL_STR = "http://www.domain.tld?query=1&query=2&query=3&query=4&query=5"
QUERY_URL = URL(QUERY_URL_STR)
URL_WITH_PATH = URL("http://www.domain.tld/req")
REL_URL = URL("/req")
QUERY_SEQ = {str(i): tuple(str(j) for j in range(10)) for i in range(10)}
Expand Down Expand Up @@ -389,28 +391,36 @@ def _run() -> None:


def test_query_string(benchmark: BenchmarkFixture) -> None:
urls = [URL(QUERY_URL_STR) for _ in range(100)]

@benchmark
def _run() -> None:
for _ in range(100):
QUERY_URL.query_string
for url in urls:
url.query_string


def test_empty_query_string(benchmark: BenchmarkFixture) -> None:
urls = [URL(BASE_URL_STR) for _ in range(100)]

@benchmark
def _run() -> None:
for _ in range(100):
BASE_URL.query_string
for url in urls:
url.query_string


def test_query(benchmark: BenchmarkFixture) -> None:
urls = [URL(QUERY_URL_STR) for _ in range(100)]

@benchmark
def _run() -> None:
for _ in range(100):
QUERY_URL.query
for url in urls:
url.query


def test_empty_query(benchmark: BenchmarkFixture) -> None:
urls = [URL(BASE_URL_STR) for _ in range(100)]

@benchmark
def _run() -> None:
for _ in range(100):
BASE_URL.query
for url in urls:
url.query

0 comments on commit 6e574b6

Please sign in to comment.