# HG changeset patch # User Gregory Szorc # Date 1474739077 25200 # Node ID 973cf6c3de3061f53f586f6a308a1310c6e47fcd # Parent 2963fba2d18a4a7857dbf4d15cf2619b9062edae 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. diff -r 2963fba2d18a -r 973cf6c3de30 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)