Compare commits

...

4 Commits

Author SHA1 Message Date
holger krekel
9877c06bf1 some reformatting and striking overall 2023-10-20 11:03:02 +02:00
holger krekel
3a403d07de some improvements, adding a bnech 2023-10-20 10:59:26 +02:00
holger krekel
115a07aecf add ping-pong bench and formatting 2023-10-20 10:28:16 +02:00
holger krekel
ae2651c441 better benchmarking and reporting 2023-10-19 02:00:02 +02:00
3 changed files with 87 additions and 27 deletions

View File

@@ -1,34 +1,60 @@
def test_tls_serialized_connect(benchmark, imap_or_smtp):
def connect():
imap_or_smtp.connect()
def test_tls_imap(benchmark, imap):
def imap_connect():
imap.connect()
benchmark(connect)
benchmark(imap_connect, 10)
def test_login(benchmark, imap_or_smtp, gencreds):
cls = imap_or_smtp.__class__
conns = []
for i in range(20):
conn = cls(imap_or_smtp.host)
conn.connect()
conns.append(conn)
def test_login_imap(benchmark, imap, gencreds):
def imap_connect_and_login():
imap.connect()
imap.login(*gencreds())
def login():
conn = conns.pop()
conn.login(*gencreds())
benchmark(login)
benchmark(imap_connect_and_login, 10)
def test_send_and_receive_10(benchmark, cmfactory, lp):
"""send many messages between two accounts"""
ac1, ac2 = cmfactory.get_online_accounts(2)
chat = cmfactory.get_accepted_chat(ac1, ac2)
def test_tls_smtp(benchmark, smtp):
def smtp_connect():
smtp.connect()
def send_10_receive_all():
for i in range(10):
chat.send_text(f"hello {i}")
for i in range(10):
ac2.wait_next_incoming_message()
benchmark(smtp_connect, 10)
benchmark(send_10_receive_all)
def test_login_smtp(benchmark, smtp, gencreds):
def smtp_connect_and_login():
smtp.connect()
smtp.login(*gencreds())
benchmark(smtp_connect_and_login, 10)
class TestDC:
def test_autoconfigure(self, benchmark, cmfactory):
def autoconfig_and_idle_ready():
cmfactory.get_online_accounts(1)
benchmark(autoconfig_and_idle_ready, 5)
def test_ping_pong(self, benchmark, cmfactory):
ac1, ac2 = cmfactory.get_online_accounts(2)
chat = cmfactory.get_accepted_chat(ac1, ac2)
def ping_pong():
chat.send_text("ping")
msg = ac2.wait_next_incoming_message()
msg.chat.send_text("pong")
ac1.wait_next_incoming_message()
benchmark(ping_pong, 3)
def test_send_10_receive_10(self, benchmark, cmfactory, lp):
ac1, ac2 = cmfactory.get_online_accounts(2)
chat = cmfactory.get_accepted_chat(ac1, ac2)
def send_10_receive_10():
for i in range(10):
chat.send_text(f"hello {i}")
for i in range(10):
ac2.wait_next_incoming_message()
benchmark(send_10_receive_10, 1)

View File

@@ -1,5 +1,6 @@
import os
import io
import time
import random
import subprocess
import imaplib
@@ -14,6 +15,10 @@ def pytest_addoption(parser):
)
def pytest_configure(config):
config._benchresults = {}
def pytest_runtest_setup(item):
markers = list(item.iter_markers(name="slow"))
if markers:
@@ -54,6 +59,35 @@ def pytest_report_header():
return ["-" * len(text), text, "-" * len(text)]
@pytest.fixture
def benchmark(request):
def bench(func, num, name=None):
if name is None:
name = func.__name__
durations = []
for i in range(num):
now = time.time()
func()
durations.append(time.time() - now)
durations.sort()
request.config._benchresults[name] = durations
return bench
def pytest_terminal_summary(terminalreporter):
tr = terminalreporter
results = tr.config._benchresults
tr.section("benchmark results")
headers = f"{'benchmark name': <30} {'median': >6}"
tr.write_line(headers)
tr.write_line("-" * len(headers))
for name, durations in results.items():
median = sorted(durations)[len(durations) // 2]
median = f"{median:2.4f}"
tr.write_line(f"{name: <30} {median: >6}")
@pytest.fixture
def imap(maildomain):
return ImapConn(maildomain)

View File

@@ -11,4 +11,4 @@ chatmaild/venv/bin/pip install --upgrade pytest build 'setuptools>=68'
chatmaild/venv/bin/pip install -e chatmaild
python3 -m venv online-tests/venv
online-tests/venv/bin/pip install pytest pytest-timeout pdbpp deltachat pytest-benchmark
online-tests/venv/bin/pip install pytest pytest-timeout pdbpp deltachat