From 192238567b88248de24333de9a3445b043ce2341 Mon Sep 17 00:00:00 2001 From: missytake Date: Mon, 16 Oct 2023 21:49:29 +0200 Subject: [PATCH] add some initial benchmarks Co-Authored-By: holger krekel --- README.md | 1 + online-tests/benchmark.py | 34 ++++++++++++++++++++++++++++++++++ scripts/bench.sh | 4 ++++ scripts/init.sh | 2 +- 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 online-tests/benchmark.py create mode 100755 scripts/bench.sh diff --git a/README.md b/README.md index bf20eb7a..87cdcb4d 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ scripts/ init.sh # create venv/other perequires deploy.sh # run pyinfra based deploy of everything test.sh # run all local and online tests + bench.sh # run performance benchmark tests ``` diff --git a/online-tests/benchmark.py b/online-tests/benchmark.py new file mode 100644 index 00000000..a23ab1bd --- /dev/null +++ b/online-tests/benchmark.py @@ -0,0 +1,34 @@ +def test_tls_serialized_connect(benchmark, imap_or_smtp): + def connect(): + imap_or_smtp.connect() + + benchmark(connect) + + +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 login(): + conn = conns.pop() + conn.login(*gencreds()) + + benchmark(login) + + +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 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(send_10_receive_all) diff --git a/scripts/bench.sh b/scripts/bench.sh new file mode 100755 index 00000000..2d95cd6b --- /dev/null +++ b/scripts/bench.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e + +online-tests/venv/bin/pytest online-tests/benchmark.py -vrx diff --git a/scripts/init.sh b/scripts/init.sh index d0553f5e..07c776c0 100755 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -10,7 +10,7 @@ chatmaild/venv/bin/pip install pytest chatmaild/venv/bin/pip install -e chatmaild python3 -m venv online-tests/venv -online-tests/venv/bin/pip install pytest pytest-timeout pdbpp deltachat +online-tests/venv/bin/pip install pytest pytest-timeout pdbpp deltachat pytest-benchmark python3 -m venv venv venv/bin/pip install build