Skip to content

Commit d4acbd6

Browse files
[PR #9900/7180ea8e backport][3.10] Add benchmark for a route that supports multiple methods (#9901)
1 parent caaf21b commit d4acbd6

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/test_benchmarks_client.py

+28
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,34 @@ def _run() -> None:
3333
loop.run_until_complete(run_client_benchmark())
3434

3535

36+
def test_one_hundred_simple_get_requests_multiple_methods_route(
37+
loop: asyncio.AbstractEventLoop,
38+
aiohttp_client: AiohttpClient,
39+
benchmark: BenchmarkFixture,
40+
) -> None:
41+
"""Benchmark 100 simple GET requests on a route with multiple methods."""
42+
message_count = 100
43+
44+
async def handler(request: web.Request) -> web.Response:
45+
return web.Response()
46+
47+
app = web.Application()
48+
# GET intentionally registered last to ensure time complexity
49+
# of the route lookup is benchmarked
50+
for method in ("DELETE", "HEAD", "OPTIONS", "PATCH", "POST", "PUT", "GET"):
51+
app.router.add_route(method, "/", handler)
52+
53+
async def run_client_benchmark() -> None:
54+
client = await aiohttp_client(app)
55+
for _ in range(message_count):
56+
await client.get("/")
57+
await client.close()
58+
59+
@benchmark
60+
def _run() -> None:
61+
loop.run_until_complete(run_client_benchmark())
62+
63+
3664
def test_one_hundred_get_requests_with_1024_chunked_payload(
3765
loop: asyncio.AbstractEventLoop,
3866
aiohttp_client: AiohttpClient,

0 commit comments

Comments
 (0)