Merge pull request #867 from chatmail/373/benchmark-filtermail-refinement

stabilize online benchmark timing adding rate-limit-aware cooldown between iterations
This commit is contained in:
373[Ø]™
2026-02-22 18:13:34 +00:00
committed by GitHub
2 changed files with 11 additions and 3 deletions

View File

@@ -1,3 +1,4 @@
import time
def test_tls_imap(benchmark, imap): def test_tls_imap(benchmark, imap):
def imap_connect(): def imap_connect():
imap.connect() imap.connect()
@@ -57,4 +58,4 @@ class TestDC:
for i in range(10): for i in range(10):
ac2._evtracker.wait_next_incoming_message() ac2._evtracker.wait_next_incoming_message()
benchmark(dc_send_10_receive_10, 5) benchmark(dc_send_10_receive_10, 5, cooldown="auto")

View File

@@ -91,15 +91,22 @@ def cm_data(request):
@pytest.fixture @pytest.fixture
def benchmark(request): def benchmark(request, chatmail_config):
def bench(func, num, name=None, reportfunc=None): def bench(func, num, name=None, reportfunc=None, cooldown=0.0):
if name is None: if name is None:
name = func.__name__ name = func.__name__
if cooldown == "auto":
per_minute = max(chatmail_config.max_user_send_per_minute, 1)
cooldown = chatmail_config.max_user_send_burst_size * 60 / per_minute
durations = [] durations = []
for i in range(num): for i in range(num):
now = time.time() now = time.time()
func() func()
durations.append(time.time() - now) durations.append(time.time() - now)
if cooldown > 0 and i + 1 < num:
# Keep post-run cooldown out of measured benchmark duration.
time.sleep(cooldown)
durations.sort() durations.sort()
request.config._benchresults[name] = (reportfunc, durations) request.config._benchresults[name] = (reportfunc, durations)