# HG changeset patch # User Pierre-Yves David # Date 1552763307 0 # Node ID 87066cf5ec0f356a69ab21f6ae35a7de8bf82c23 # Parent b900b392c1cc05bacbb41d0047b20abb8544c6e7 perf: more flexible implementation for checking stop conditions We want to make this logic simpler to configure. The first step is to stop hard-coding every values. diff -r b900b392c1cc -r 87066cf5ec0f contrib/perf.py --- a/contrib/perf.py Mon Mar 25 08:41:02 2019 -0700 +++ b/contrib/perf.py Sat Mar 16 19:08:27 2019 +0000 @@ -315,12 +315,20 @@ a, b = ostart, ostop r.append((cstop - cstart, b[0] - a[0], b[1]-a[1])) + +# list of stop condition (elapsed time, minimal run count) +DEFAULTLIMITS = ( + (3.0, 100), + (10.0, 3), +) + def _timer(fm, func, setup=None, title=None, displayall=False): gc.collect() results = [] begin = util.timer() count = 0 - while True: + keepgoing = True + while keepgoing: if setup is not None: setup() with timeone() as item: @@ -328,10 +336,12 @@ count += 1 results.append(item[0]) cstop = util.timer() - if cstop - begin > 3 and count >= 100: - break - if cstop - begin > 10 and count >= 3: - break + # Look for a stop condition. + elapsed = cstop - begin + for t, mincount in DEFAULTLIMITS: + if elapsed >= t and count >= mincount: + keepgoing = False + break formatone(fm, results, title=title, result=r, displayall=displayall)