|
| 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