some improvements, adding a bnech

This commit is contained in:
holger krekel
2023-10-20 10:59:26 +02:00
parent 1ae6291d06
commit 03442bc115
2 changed files with 30 additions and 21 deletions

View File

@@ -28,29 +28,34 @@ def test_login_smtp(benchmark, smtp, gencreds):
benchmark(smtp_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)
class TestDC:
def test_autoconfigure(self, benchmark, cmfactory):
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()
def autoconfig_and_idle_ready():
cmfactory.get_online_accounts(1)
benchmark(send_10_receive_all, 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 test_ping_pong(benchmark, cmfactory, lp):
"""send many messages between two accounts"""
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()
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)
benchmark(ping_pong, 5)
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

@@ -79,10 +79,14 @@ 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():
overall = sum(durations)
median = sorted(durations)[len(durations) // 2]
tr.write_line(f"{name: <30} {median:2.4f} seconds")
median = f'{median:2.4f}'
tr.write_line(f"{name: <30} {median: >6}")
@pytest.fixture