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