File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change 6
6
from pytest_codspeed import BenchmarkFixture
7
7
8
8
from aiohttp import DataQueue
9
- from aiohttp ._websocket .helpers import MSG_SIZE
9
+ from aiohttp ._websocket .helpers import MSG_SIZE , PACK_LEN3
10
10
from aiohttp .base_protocol import BaseProtocol
11
11
from aiohttp .http_websocket import (
12
12
WebSocketReader ,
16
16
)
17
17
18
18
19
+ def test_read_large_binary_websocket_messages (
20
+ loop : asyncio .AbstractEventLoop , benchmark : BenchmarkFixture
21
+ ) -> None :
22
+ """Read one hundred large binary websocket messages."""
23
+ queue : DataQueue [WSMessage ] = DataQueue (loop = loop )
24
+ reader = WebSocketReader (queue , max_msg_size = 2 ** 18 )
25
+
26
+ # PACK3 has a minimum message length of 2**16 bytes.
27
+ message = b"x" * ((2 ** 16 ) + 1 )
28
+ msg_length = len (message )
29
+ first_byte = 0x80 | 0 | WSMsgType .BINARY .value
30
+ header = PACK_LEN3 (first_byte , 127 , msg_length )
31
+ raw_message = header + message
32
+ feed_data = reader .feed_data
33
+
34
+ @benchmark
35
+ def _run () -> None :
36
+ for _ in range (100 ):
37
+ feed_data (raw_message )
38
+
39
+
19
40
def test_read_one_hundred_websocket_text_messages (
20
41
loop : asyncio .AbstractEventLoop , benchmark : BenchmarkFixture
21
42
) -> None :
You can’t perform that action at this time.
0 commit comments