@@ -40,6 +40,37 @@ def _run() -> None:
40
40
loop .run_until_complete (run_websocket_benchmark ())
41
41
42
42
43
+ def test_one_thousand_round_trip_websocket_binary_messages (
44
+ loop : asyncio .AbstractEventLoop ,
45
+ aiohttp_client : AiohttpClient ,
46
+ benchmark : BenchmarkFixture ,
47
+ ) -> None :
48
+ """Benchmark round trip of 1000 WebSocket binary messages."""
49
+ message_count = 1000
50
+
51
+ async def handler (request : web .Request ) -> web .WebSocketResponse :
52
+ ws = web .WebSocketResponse ()
53
+ await ws .prepare (request )
54
+ for _ in range (message_count ):
55
+ await ws .send_bytes (b"answer" )
56
+ await ws .close ()
57
+ return ws
58
+
59
+ app = web .Application ()
60
+ app .router .add_route ("GET" , "/" , handler )
61
+
62
+ async def run_websocket_benchmark () -> None :
63
+ client = await aiohttp_client (app )
64
+ resp = await client .ws_connect ("/" )
65
+ for _ in range (message_count ):
66
+ await resp .receive ()
67
+ await resp .close ()
68
+
69
+ @benchmark
70
+ def _run () -> None :
71
+ loop .run_until_complete (run_websocket_benchmark ())
72
+
73
+
43
74
def test_one_thousand_large_round_trip_websocket_text_messages (
44
75
loop : asyncio .AbstractEventLoop ,
45
76
aiohttp_client : AiohttpClient ,
0 commit comments