Skip to content

Commit

Permalink
Add compressed WebSocketWriter benchmark (#9799)
Browse files Browse the repository at this point in the history
(cherry picked from commit d40b183)
  • Loading branch information
bdraco authored and patchback[bot] committed Nov 11, 2024
1 parent c6270f2 commit b0e124b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/test_benchmarks_http_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

0 comments on commit b0e124b

Please sign in to comment.