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 benchmarks for creating web responses #9940

Merged
merged 3 commits into from
Nov 17, 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
62 changes: 62 additions & 0 deletions tests/test_benchmarks_web_response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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()
Loading