Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add url dispatcher benchmark for resolving root route when exists many plain routes in the subtree #9954

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions tests/test_benchmarks_web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,44 @@ def _run() -> None:
loop.run_until_complete(run_url_dispatcher_benchmark())


def test_resolve_root_route_with_many_fixed_routes(
loop: asyncio.AbstractEventLoop,
benchmark: BenchmarkFixture,
) -> None:
"""Resolve top level PlainResources route 100 times."""
resolve_count = 100

async def handler(request: web.Request) -> NoReturn:
assert False

app = web.Application()
app.router.add_route("GET", "/", handler)
for count in range(250):
app.router.add_route("GET", f"/api/server/dispatch/{count}/update", handler)
app.router.add_route("GET", f"/api/server/dispatch/{count}", handler)
app.router.add_route("GET", "/api/server/dispatch", handler)
app.router.add_route("GET", "/api/server", handler)
app.router.add_route("GET", "/api", handler)
app.freeze()
router = app.router
request = _mock_request(method="GET", path="/")

async def run_url_dispatcher_benchmark() -> Optional[web.UrlMappingMatchInfo]:
ret = None
for _ in range(resolve_count):
ret = await router.resolve(request)

return ret

ret = loop.run_until_complete(run_url_dispatcher_benchmark())
assert ret is not None
assert ret.get_info()["path"] == "/", ret.get_info()

@benchmark
def _run() -> None:
loop.run_until_complete(run_url_dispatcher_benchmark())


def test_resolve_static_root_route(
loop: asyncio.AbstractEventLoop,
benchmark: BenchmarkFixture,
Expand Down
Loading