From b0e124bd827ad313044fd32d1d0d46658cd46687 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 11 Nov 2024 08:18:10 -0600 Subject: [PATCH 1/2] Add compressed WebSocketWriter benchmark (#9799) (cherry picked from commit d40b1839dbd794db89b82dd36530cd40718b8b07) --- tests/test_benchmarks_http_websocket.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/test_benchmarks_http_websocket.py b/tests/test_benchmarks_http_websocket.py index cc1006c7381..140e5fb73c9 100644 --- a/tests/test_benchmarks_http_websocket.py +++ b/tests/test_benchmarks_http_websocket.py @@ -115,3 +115,19 @@ async def _send_one_hundred_websocket_text_messages() -> None: @benchmark def _run() -> None: loop.run_until_complete(_send_one_hundred_websocket_text_messages()) + + +def test_send_one_hundred_websocket_compressed_messages( + loop: asyncio.AbstractEventLoop, benchmark: BenchmarkFixture +) -> None: + """Benchmark sending 100 WebSocket text messages.""" + writer = WebSocketWriter(MockProtocol(loop=loop), MockTransport(), compress=15) + raw_message = b"Hello, World!" * 100 + + async def _send_one_hundred_websocket_compressed_messages() -> None: + for _ in range(100): + await writer.send_frame(raw_message, WSMsgType.BINARY) + + @benchmark + def _run() -> None: + loop.run_until_complete(_send_one_hundred_websocket_compressed_messages()) From 4109194ab961c7fc45583ee34751894352e4c75c Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 11 Nov 2024 08:27:33 -0600 Subject: [PATCH 2/2] Update tests/test_benchmarks_http_websocket.py --- tests/test_benchmarks_http_websocket.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_benchmarks_http_websocket.py b/tests/test_benchmarks_http_websocket.py index 140e5fb73c9..7ff04199d24 100644 --- a/tests/test_benchmarks_http_websocket.py +++ b/tests/test_benchmarks_http_websocket.py @@ -120,7 +120,7 @@ def _run() -> None: def test_send_one_hundred_websocket_compressed_messages( loop: asyncio.AbstractEventLoop, benchmark: BenchmarkFixture ) -> None: - """Benchmark sending 100 WebSocket text messages.""" + """Benchmark sending 100 WebSocket compressed messages.""" writer = WebSocketWriter(MockProtocol(loop=loop), MockTransport(), compress=15) raw_message = b"Hello, World!" * 100