Skip to content

Commit 6cf4497

Browse files
[PR #9940/9ca1a581 backport][3.11] Add benchmarks for creating web responses (#9942)
Co-authored-by: J. Nick Koston <[email protected]>
1 parent 9c81667 commit 6cf4497

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

tests/test_benchmarks_web_response.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
"""codspeed benchmarks for the web responses."""
2+
3+
from pytest_codspeed import BenchmarkFixture
4+
5+
from aiohttp import web
6+
7+
8+
def test_simple_web_response(benchmark: BenchmarkFixture) -> None:
9+
"""Benchmark creating 100 simple web.Response."""
10+
response_count = 100
11+
12+
@benchmark
13+
def _run() -> None:
14+
for _ in range(response_count):
15+
web.Response()
16+
17+
18+
def test_web_response_with_headers(benchmark: BenchmarkFixture) -> None:
19+
"""Benchmark creating 100 web.Response with headers."""
20+
response_count = 100
21+
headers = {
22+
"Content-Type": "text/plain",
23+
"Server": "aiohttp",
24+
"Date": "Sun, 01 Aug 2021 12:00:00 GMT",
25+
}
26+
27+
@benchmark
28+
def _run() -> None:
29+
for _ in range(response_count):
30+
web.Response(headers=headers)
31+
32+
33+
def test_web_response_with_bytes_body(
34+
benchmark: BenchmarkFixture,
35+
) -> None:
36+
"""Benchmark creating 100 web.Response with bytes."""
37+
response_count = 100
38+
39+
@benchmark
40+
def _run() -> None:
41+
for _ in range(response_count):
42+
web.Response(body=b"Hello, World!")
43+
44+
45+
def test_web_response_with_text_body(benchmark: BenchmarkFixture) -> None:
46+
"""Benchmark creating 100 web.Response with text."""
47+
response_count = 100
48+
49+
@benchmark
50+
def _run() -> None:
51+
for _ in range(response_count):
52+
web.Response(text="Hello, World!")
53+
54+
55+
def test_simple_web_stream_response(benchmark: BenchmarkFixture) -> None:
56+
"""Benchmark creating 100 simple web.StreamResponse."""
57+
response_count = 100
58+
59+
@benchmark
60+
def _run() -> None:
61+
for _ in range(response_count):
62+
web.StreamResponse()

0 commit comments

Comments
 (0)