Mercurial > public > mercurial-scm > hg-stable
diff contrib/perf.py @ 39007:1601afbb573c
perf: add a command to benchmark linelog edits
The use pattern of creating a linelog is usually by calling "replacelines"
multiple times. Add a command to benchmark it.
Differential Revision: https://phab.mercurial-scm.org/D4148
author | Jun Wu <quark@fb.com> |
---|---|
date | Mon, 06 Aug 2018 18:56:24 -0700 |
parents | 0a57945aaf7f |
children | a1f694779b2f |
line wrap: on
line diff
--- a/contrib/perf.py Mon Aug 06 18:56:24 2018 -0700 +++ b/contrib/perf.py Mon Aug 06 18:56:24 2018 -0700 @@ -889,6 +889,38 @@ timer(lambda: len(repo.lookup(rev))) fm.end() +@command('perflinelogedits', + [('n', 'edits', 10000, 'number of edits'), + ('', 'max-hunk-lines', 10, 'max lines in a hunk'), + ], norepo=True) +def perflinelogedits(ui, **opts): + from mercurial import linelog + + edits = opts['edits'] + maxhunklines = opts['max_hunk_lines'] + + maxb1 = 100000 + random.seed(0) + randint = random.randint + currentlines = 0 + arglist = [] + for rev in xrange(edits): + a1 = randint(0, currentlines) + a2 = randint(a1, min(currentlines, a1 + maxhunklines)) + b1 = randint(0, maxb1) + b2 = randint(b1, b1 + maxhunklines) + currentlines += (b2 - b1) - (a2 - a1) + arglist.append((rev, a1, a2, b1, b2)) + + def d(): + ll = linelog.linelog() + for args in arglist: + ll.replacelines(*args) + + timer, fm = gettimer(ui, opts) + timer(d) + fm.end() + @command('perfrevrange', formatteropts) def perfrevrange(ui, repo, *specs, **opts): timer, fm = gettimer(ui, opts)