Skip to content

Commit

Permalink
Merge branch 'master' into fix-subapps-gitapi-benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov authored Nov 17, 2024
2 parents 7019be5 + 69ca7df commit 0e3d123
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ long_description = file: README.rst
long_description_content_type = text/x-rst
maintainer = aiohttp team <team@aiohttp.org>
maintainer_email = team@aiohttp.org
license = Apache 2
license = Apache-2.0
license_files = LICENSE.txt
classifiers =
Development Status :: 5 - Production/Stable
Expand Down
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()

0 comments on commit 0e3d123

Please sign in to comment.