8000 Add `asyncio_tcp` benchmark by kumaraditya303 · Pull Request #254 · python/pyperformance · GitHub
[go: up one dir, main page]

Skip to content

Add asyncio_tcp benchmark #254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyperformance/data-files/benchmarks/MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ async_tree <local>
async_tree_cpu_io_mixed <local:async_tree>
async_tree_io <local:async_tree>
async_tree_memoization <local:async_tree>
asyncio_tcp <local>
concurrent_imap <local>
coroutines <local>
coverage <local>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[project]
name = "pyperformance_bm_asyncio_tcp"
requires-python = ">=3.8"
dependencies = ["pyperf"]
urls = {repository = "https://github.com/python/pyperformance"}
dynamic = ["version"]

[tool.pyperformance]
name = "asyncio_tcp"
79AE
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
Benchmark for asyncio TCP server and client performance
transferring 10MB of data.

Author: Kumar Aditya
"""


import asyncio
from pyperf import Runner


CHUNK_SIZE = 1024 ** 2 * 10


async def handle_echo(reader: asyncio.StreamReader,
writer: asyncio.StreamWriter) -> None:
data = b'x' * CHUNK_SIZE
for _ in range(100):
writer.write(data)
await writer.drain()
writer.close()
await writer.wait_closed()


async def main() -> None:
server = await asyncio.start_server(handle_echo, '127.0.0.1', 8882)

async with server:
asyncio.create_task(server.start_serving())
reader, writer = await asyncio.open_connection('127.0.0.1', 8882)
while True:
data = await reader.read(CHUNK_SIZE)
if not data:
break
writer.close()
await writer.wait_closed()

if __name__ == '__main__':
runner = Runner()
runner.bench_async_func('asyncio_tcp', main)
0