perf: add --reverse to perfrevlog
authorGregory Szorc <gregory.szorc@gmail.com>
Sat, 24 Sep 2016 10:44:37 -0700
changeset 30019 973cf6c3de30
parent 30018 2963fba2d18a
child 30020 bd6df07ccc24
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.
contrib/perf.py
--- a/contrib/perf.py	Sat Sep 24 19:58:23 2016 +0900
+++ b/contrib/perf.py	Sat Sep 24 10:44:37 2016 -0700
@@ -580,9 +580,10 @@
 
 @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
@@ -591,11 +592,20 @@
     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)