1
1
"""codspeed benchmarks for http websocket."""
2
2
3
3
import asyncio
4
+ from typing import Union
4
5
5
6
from pytest_codspeed import BenchmarkFixture
6
7
7
8
from aiohttp import DataQueue
9
+ from aiohttp ._websocket .helpers import MSG_SIZE
8
10
from aiohttp .base_protocol import BaseProtocol
9
11
from aiohttp .http_websocket import (
10
12
WebSocketReader ,
@@ -41,7 +43,7 @@ def is_closing(self) -> bool:
41
43
"""Swallow is_closing."""
42
44
return False
43
45
44
- def write (self , data : bytes ) -> None :
46
+ def write (self , data : Union [ bytes , bytearray , memoryview ] ) -> None :
45
47
"""Swallow writes."""
46
48
47
49
@@ -67,6 +69,22 @@ def _run() -> None:
67
69
loop .run_until_complete (_send_one_hundred_websocket_text_messages ())
68
70
69
71
72
+ def test_send_one_hundred_large_websocket_text_messages (
73
+ loop : asyncio .AbstractEventLoop , benchmark : BenchmarkFixture
74
+ ) -> None :
75
+ """Benchmark sending 100 WebSocket text messages."""
76
+ writer = WebSocketWriter (MockProtocol (loop = loop ), MockTransport ())
77
+ raw_message = b"x" * MSG_SIZE * 4
78
+
79
+ async def _send_one_hundred_websocket_text_messages () -> None :
80
+ for _ in range (100 ):
81
+ await writer .send_frame (raw_message , WSMsgType .TEXT )
82
+
83
+ @benchmark
84
+ def _run () -> None :
85
+ loop .run_until_complete (_send_one_hundred_websocket_text_messages ())
86
+
87
+
70
88
def test_send_one_hundred_websocket_text_messages_with_mask (
71
89
loop : asyncio .AbstractEventLoop , benchmark : BenchmarkFixture
72
90
) -> None :
0 commit comments