File tree Expand file tree Collapse file tree
pyperformance/data-files/benchmarks Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ async_tree_eager_io_tg <local:async_tree>
2121async_tree_eager_memoization_tg <local:async_tree>
2222asyncio_tcp <local>
2323asyncio_tcp_ssl <local:asyncio_tcp>
24+ asyncio_websockets <local>
2425concurrent_imap <local>
2526coroutines <local>
2627coverage <local>
Original file line number Diff line number Diff line change 1+ [project ]
2+ name = " pyperformance_bm_asyncio_websockets"
3+ requires-python = " >=3.8"
4+ dependencies = [" pyperf" , " websockets" ]
5+ urls = {repository = " https://github.com/python/pyperformance" }
6+ dynamic = [" version" ]
7+
8+ [tool .pyperformance ]
9+ name = " asyncio_websockets"
Original file line number Diff line number Diff line change 1+ websockets == 11.0.3
Original file line number Diff line number Diff line change 1+ """
2+ Benchmark for asyncio websocket server and client performance
3+ transferring 10MB of data.
4+ """
5+
6+ import pyperf
7+ import websockets .server
8+ import websockets .client
9+ import asyncio
10+
11+ CHUNK_SIZE = 1024
12+ DATA = b"x" * CHUNK_SIZE
13+
14+ stop : asyncio .Event
15+
16+
17+ async def handler (websocket ) -> None :
18+ for _ in range (100 ):
19+ data = await websocket .recv ()
20+ assert data == DATA
21+
22+ stop .set ()
23+
24+
25+ async def main () -> None :
26+ global stop
27+ t0 = pyperf .perf_counter ()
28+ stop = asyncio .Event ()
29+ async with websockets .server .serve (handler , "" , 8001 ):
30+ async with websockets .client .connect ("ws://localhost:8001" ) as ws :
31+ await asyncio .gather (* [ws .send (DATA ) for _ in range (100 )])
32+ await stop .wait ()
33+ return pyperf .perf_counter () - t0
34+
35+
36+ if __name__ == "__main__" :
37+ runner = pyperf .Runner ()
38+ runner .metadata ['description' ] = "Benchmark asyncio websockets"
39+ runner .bench_async_func ('asyncio_websockets' , main )
You can’t perform that action at this time.
0 commit comments