From 437287fadc2cb741a495a3e6f35607d387342e6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?373=5B=C3=98=5D=E2=84=A2?= <151577046+ccclxxiii@users.noreply.github.com> Date: Sun, 22 Feb 2026 15:55:03 +0000 Subject: [PATCH] feat(tests): add optional benchmark cooldown between iterations --- cmdeploy/src/cmdeploy/tests/plugin.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmdeploy/src/cmdeploy/tests/plugin.py b/cmdeploy/src/cmdeploy/tests/plugin.py index 60d27efc..257533e2 100644 --- a/cmdeploy/src/cmdeploy/tests/plugin.py +++ b/cmdeploy/src/cmdeploy/tests/plugin.py @@ -92,7 +92,7 @@ def cm_data(request): @pytest.fixture def benchmark(request): - def bench(func, num, name=None, reportfunc=None): + def bench(func, num, name=None, reportfunc=None, cooldown=0.0): if name is None: name = func.__name__ durations = [] @@ -100,6 +100,9 @@ def benchmark(request): now = time.time() func() 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() request.config._benchresults[name] = (reportfunc, durations)