changeset 30019:973cf6c3de30

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.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 24 Sep 2016 10:44:37 -0700
parents 2963fba2d18a
children bd6df07ccc24
files contrib/perf.py
diffstat 1 files changed, 14 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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)