perf: more flexible implementation for checking stop conditions
authorPierre-Yves David <pierre-yves.david@octobus.net>
Sat, 16 Mar 2019 19:08:27 +0000
changeset 42017 87066cf5ec0f
parent 42016 b900b392c1cc
child 42018 0e6422942c84
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.
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)