Patchwork [4,of,6,"] perf: more flexible implementation for checking stop conditions

login
register
mail settings
Submitter Pierre-Yves David
Date March 25, 2019, 1:19 p.m.
Message ID <89dba0ac07a2c581f527.1553519963@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/39382/
State Accepted
Headers show

Comments

Pierre-Yves David - March 25, 2019, 1:19 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1552763307 0
#      Sat Mar 16 19:08:27 2019 +0000
# Node ID 89dba0ac07a2c581f527c807c61c36883013d323
# Parent  0f03ddf89818a3561dcd9b7a186ba7bcd2d10ed3
# EXP-Topic perf-run
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 89dba0ac07a2
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.

Patch

diff --git a/contrib/perf.py b/contrib/perf.py
--- a/contrib/perf.py
+++ b/contrib/perf.py
@@ -315,12 +315,20 @@  def timeone():
     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 @@  def _timer(fm, func, setup=None, title=N
         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)