forked from python/pyperformance
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
asyncio_tcp
benchmark (python#254)
Signed-off-by: Pablo Galindo <[email protected]>
- Loading branch information
1 parent
340008c
commit e57da59
Showing
15 changed files
with
68 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
] | ||
|
||
|
||
from collections import namedtuple | ||
import os.path | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
import os | ||
import os.path | ||
import shlex | ||
import subprocess | ||
import sys | ||
|
||
from . import _utils, _pythoninfo | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import csv | ||
import os.path | ||
import math | ||
import sys | ||
|
||
import pyperf | ||
import statistics | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
pyperformance/data-files/benchmarks/bm_asyncio_tcp/pyproject.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
44 changes: 44 additions & 0 deletions
44
pyperformance/data-files/benchmarks/bm_asyncio_tcp/run_benchmark.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
""" | ||
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) | ||
data_len = 0 | ||
while True: | ||
data = await reader.read(CHUNK_SIZE) | ||
if not data: | ||
break | ||
data_len += len(data) | ||
assert data_len == CHUNK_SIZE * 100 | ||
writer.close() | ||
await writer.wait_closed() | ||
|
||
if __name__ == '__main__': | ||
runner = Runner() | ||
runner.bench_async_func('asyncio_tcp', main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
|
||
import contextlib | ||
from pathlib import Path | ||
import time | ||
|
||
import docutils | ||
from docutils import core | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
""" | ||
|
||
import pyperf | ||
from this_is import en_us | ||
|
||
|
||
def bench(): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import os | ||
import os.path | ||
import shutil | ||
import sys | ||
import textwrap | ||
import unittest | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters