File tree 3 files changed +54
-0
lines changed
pyperformance/data-files/benchmarks 3 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ async_tree <local>
7
7
async_tree_cpu_io_mixed <local:async_tree>
8
8
async_tree_io <local:async_tree>
9
9
async_tree_memoization <local:async_tree>
10
+ asyncio_tcp <local>
10
11
concurrent_imap <local>
11
12
coroutines <local>
12
13
coverage <local>
Original file line number Diff line number Diff line change
1
+ [project ]
2
+ name = " pyperformance_bm_asyncio_tcp"
3
+ requires-python = " >=3.8"
4
+ dependencies = [" pyperf" ]
5
+ urls = {repository = " https://github.com/python/pyperformance" }
6
+ dynamic = [" version" ]
7
+
8
+ [tool .pyperformance ]
9
+ name = " asyncio_tcp"
Original file line number Diff line number Diff line change
1
+ """
2
+ Benchmark for asyncio TCP server and client performance
3
+ transferring 10MB of data.
4
+
5
+ Author: Kumar Aditya
6
+ """
7
+
8
+
9
+ import asyncio
10
+ from pyperf import Runner
11
+
12
+
13
+ CHUNK_SIZE = 1024 ** 2 * 10
14
+
15
+
16
+ async def handle_echo (reader : asyncio .StreamReader ,
17
+ writer : asyncio .StreamWriter ) -> None :
18
+ data = b'x' * CHUNK_SIZE
19
+ for _ in range (100 ):
20
+ writer .write (data )
21
+ await writer .drain ()
22
+ writer .close ()
23
+ await writer .wait_closed ()
24
+
25
+
26
+ async def main () -> None :
27
+ server = await asyncio .start_server (handle_echo , '127.0.0.1' , 8882 )
28
+
29
+ async with server :
30
+ asyncio .create_task (server .start_serving ())
31
+ reader , writer = await asyncio .open_connection ('127.0.0.1' , 8882 )
32
+ data_len = 0
33
+ while True :
34
+ data = await reader .read (CHUNK_SIZE )
35
+ if not data :
36
+ break
37
+ data_len += len (data )
38
+ assert data_len == CHUNK_SIZE * 100
39
+ writer .close ()
40
+ await writer .wait_closed ()
41
+
42
+ if __name__ == '__main__' :
43
+ runner = Runner ()
44
+ runner .bench_async_func ('asyncio_tcp' , main )
You can’t perform that action at this time.
0 commit comments