feat(tests): add optional benchmark cooldown between iterations

This commit is contained in:
373[Ø]™
2026-02-22 15:55:03 +00:00
committed by GitHub
parent 0ad679997a
commit 437287fadc

View File

@@ -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)