Patchwork [6,of,8] perf: extract result formatting in its own function

login
register
mail settings
Submitter Boris Feld
Date Oct. 11, 2018, 8:01 a.m.
Message ID <38eab0ea4fb465c5e1c9.1539244909@localhost.localdomain>
Download mbox | patch
Permalink /patch/35629/
State Accepted
Headers show

Comments

Boris Feld - Oct. 11, 2018, 8:01 a.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1538556416 -7200
#      Wed Oct 03 10:46:56 2018 +0200
# Node ID 38eab0ea4fb465c5e1c9565b3824e7d15edf150e
# Parent  236a33954a26bae0735388b2f7a34fa8d8606195
# EXP-Topic revlog-perf
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 38eab0ea4fb4
perf: extract result formatting in its own function

This will make it easier to reuse in another changesets.

Patch

diff --git a/contrib/perf.py b/contrib/perf.py
--- a/contrib/perf.py
+++ b/contrib/perf.py
@@ -301,12 +301,19 @@  def _timer(fm, func, title=None, display
         if cstop - begin > 10 and count >= 3:
             break
 
+    formatone(fm, results, title=title, result=r,
+              displayall=displayall)
+
+def formatone(fm, timings, title=None, result=None, displayall=False):
+
+    count = len(timings)
+
     fm.startitem()
 
     if title:
         fm.write(b'title', b'! %s\n', title)
-    if r:
-        fm.write(b'result', b'! result: %s\n', r)
+    if result:
+        fm.write(b'result', b'! result: %s\n', result)
     def display(role, entry):
         prefix = b''
         if role != b'best':
@@ -318,15 +325,15 @@  def _timer(fm, func, title=None, display
         fm.write(prefix + b'sys',  b' sys %f', entry[2])
         fm.write(prefix + b'count',  b' (%s of %%d)' % role, count)
         fm.plain(b'\n')
-    results.sort()
-    min_val = results[0]
+    timings.sort()
+    min_val = timings[0]
     display(b'best', min_val)
     if displayall:
-        max_val = results[-1]
+        max_val = timings[-1]
         display(b'max', max_val)
-        avg = tuple([sum(x) / count for x in zip(*results)])
+        avg = tuple([sum(x) / count for x in zip(*timings)])
         display(b'avg', avg)
-        median = results[len(results) // 2]
+        median = timings[len(timings) // 2]
         display(b'median', median)
 
 # utilities for historical portability