-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a benchmark for web.FileResponse
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"""codspeed benchmarks for the web responses.""" | ||
|
||
import asyncio | ||
import pathlib | ||
|
||
from pytest_codspeed import BenchmarkFixture | ||
|
||
from aiohttp import web | ||
from aiohttp.pytest_plugin import AiohttpClient | ||
|
||
|
||
def test_simple_web_response( | ||
loop: asyncio.AbstractEventLoop, | ||
aiohttp_client: AiohttpClient, | ||
benchmark: BenchmarkFixture, | ||
) -> None: | ||
"""Benchmark creating 100 simple web.Response.""" | ||
response_count = 100 | ||
filepath = pathlib.Path(__file__).parent / "sample.txt" | ||
|
||
async def handler(request: web.Request) -> web.FileResponse: | ||
return web.FileResponse(path=filepath) | ||
|
||
app = web.Application() | ||
app.router.add_route("GET", "/", handler) | ||
|
||
async def run_file_resonse_benchmark() -> None: | ||
client = await aiohttp_client(app) | ||
for _ in range(response_count): | ||
await client.get("/") | ||
await client.close() | ||
|
||
@benchmark | ||
def _run() -> None: | ||
loop.run_until_complete(run_file_resonse_benchmark()) |