File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ """codspeed benchmarks for web middlewares."""
2
+
3
+ import asyncio
4
+
5
+ from pytest_codspeed import BenchmarkFixture
6
+
7
+ from aiohttp import web
8
+ from aiohttp .pytest_plugin import AiohttpClient
9
+ from aiohttp .typedefs import Handler
10
+
11
+
12
+ def test_ten_web_middlewares (
13
+ benchmark : BenchmarkFixture ,
14
+ loop : asyncio .AbstractEventLoop ,
15
+ aiohttp_client : AiohttpClient ,
16
+ ) -> None :
17
+ """Benchmark 100 requests with 10 middlewares."""
18
+ message_count = 100
19
+
20
+ async def handler (request : web .Request ) -> web .Response :
21
+ return web .Response ()
22
+
23
+ app = web .Application ()
24
+ app .router .add_route ("GET" , "/" , handler )
25
+
26
+ class MiddlewareClass :
27
+ @web .middleware
28
+ async def call (
29
+ self , request : web .Request , handler : Handler
30
+ ) -> web .StreamResponse :
31
+ return await handler (request )
32
+
33
+ for _ in range (10 ):
34
+ app .middlewares .append (MiddlewareClass ().call )
35
+
36
+ async def run_client_benchmark () -> None :
37
+ client = await aiohttp_client (app )
38
+ for _ in range (message_count ):
39
+ await client .get ("/" )
40
+ await client .close ()
41
+
42
+ @benchmark
43
+ def _run () -> None :
44
+ loop .run_until_complete (run_client_benchmark ())
You can’t perform that action at this time.
0 commit comments