revsetbenchmarks: factor out result output into a function
authorPierre-Yves David <pierre-yves.david@fb.com>
Tue, 09 Jun 2015 16:57:18 -0700
changeset 25531 371d8afc9144
parent 25530 94efef10b63f
child 25532 1311aee85dcf
revsetbenchmarks: factor out result output into a function This will make update of the output easier.
contrib/revsetbenchmarks.py
--- a/contrib/revsetbenchmarks.py	Tue Jun 09 16:48:29 2015 -0700
+++ b/contrib/revsetbenchmarks.py	Tue Jun 09 16:57:18 2015 -0700
@@ -92,12 +92,15 @@
     check_call(['hg', 'log', '--rev', str(rev), '--template',
                '{desc|firstline}\n'])
 
-def formatresult(data):
-    """format the data dict into a line of text for humans"""
-    return ("wall %f comb %f user %f sys %f (best of %d)"
-            % (data['wall'], data['comb'], data['user'],
-               data['sys'], data['count']))
+def printresult(idx, data, maxidx):
+    """print a line of result to stdout"""
+    mask = '%i) %s'
 
+    out = ("wall %f comb %f user %f sys %f (best of %d)"
+           % (data['wall'], data['comb'], data['user'],
+              data['sys'], data['count']))
+
+    print mask % (idx, out)
 
 def getrevs(spec):
     """get the list of rev matched by a revset"""
@@ -156,7 +159,7 @@
     for idx, rset in enumerate(revsets):
         data = perf(rset, target=options.repo)
         res.append(data)
-        print "%i)" % idx, formatresult(data)
+        printresult(idx, data, len(revsets))
         sys.stdout.flush()
     print "----------------------------"
 
@@ -180,5 +183,5 @@
 
     print "revset #%i: %s" % (ridx, rset)
     for idx, data in enumerate(results):
-        print '%i) %s' % (idx, formatresult(data[ridx]))
+        printresult(idx, data[ridx], len(results))
     print