Patchwork [1,of,4] perf: add --reverse to perfrevlog

login
register
mail settings
Submitter Gregory Szorc
Date Sept. 24, 2016, 7:37 p.m.
Message ID <4567ac4e7248ace44519.1474745836@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/16779/
State Accepted
Headers show

Comments

Gregory Szorc - Sept. 24, 2016, 7:37 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1474739077 25200
#      Sat Sep 24 10:44:37 2016 -0700
# Node ID 4567ac4e7248ace445195b9de10720bf54d47a7d
# Parent  b19c2679289cc5e9b51eac84b63c304bda0096dc
perf: add --reverse to perfrevlog

It can be useful to know how fast we can read revisions from a revlog
in reverse. This operation tends to occur in `hg log` commands,
for example.

Patch

diff --git a/contrib/perf.py b/contrib/perf.py
--- a/contrib/perf.py
+++ b/contrib/perf.py
@@ -575,32 +575,42 @@  def perfdiffwd(ui, repo, **opts):
             commands.diff(ui, repo, **opts)
             ui.popbuffer()
         title = 'diffopts: %s' % (diffopt and ('-' + diffopt) or 'none')
         timer(d, title)
     fm.end()
 
 @command('perfrevlog', revlogopts + formatteropts +
          [('d', 'dist', 100, 'distance between the revisions'),
-          ('s', 'startrev', 0, 'revision to start reading at')],
+          ('s', 'startrev', 0, 'revision to start reading at'),
+          ('', 'reverse', False, 'read in reverse')],
          '-c|-m|FILE')
-def perfrevlog(ui, repo, file_=None, startrev=0, **opts):
+def perfrevlog(ui, repo, file_=None, startrev=0, reverse=False, **opts):
     """Benchmark reading a series of revisions from a revlog.
 
     By default, we read every ``-d/--dist`` revision from 0 to tip of
     the specified revlog.
 
     The start revision can be defined via ``-s/--startrev``.
     """
     timer, fm = gettimer(ui, opts)
-    dist = opts['dist']
     _len = getlen(ui)
+
     def d():
         r = cmdutil.openrevlog(repo, 'perfrevlog', file_, opts)
-        for x in xrange(startrev, _len(r), dist):
+
+        startrev = 0
+        endrev = _len(r)
+        dist = opts['dist']
+
+        if reverse:
+            startrev, endrev = endrev, startrev
+            dist = -1 * dist
+
+        for x in xrange(startrev, endrev, dist):
             r.revision(r.node(x))
 
     timer(d)
     fm.end()
 
 @command('perfrevlogrevision', revlogopts + formatteropts +
          [('', 'cache', False, 'use caches instead of clearing')],
          '-c|-m|FILE REV')