contrib/perf.py
changeset 18237 4132dc9bd5c4
parent 18236 819520ca213d
child 18238 1f991e625d01
--- a/contrib/perf.py	Fri Jan 04 19:18:12 2013 +0100
+++ b/contrib/perf.py	Fri Jan 04 19:20:51 2013 +0100
@@ -4,6 +4,9 @@
 from mercurial import cmdutil, scmutil, util, match, commands
 import time, os, sys
 
+cmdtable = {}
+command = cmdutil.command(cmdtable)
+
 def timer(func, title=None):
     results = []
     begin = time.time()
@@ -29,6 +32,7 @@
     sys.stderr.write("! wall %f comb %f user %f sys %f (best of %d)\n"
                      % (m[0], m[1] + m[2], m[1], m[2], count))
 
+@command('perfwalk')
 def perfwalk(ui, repo, *pats):
     try:
         m = scmutil.match(repo[None], pats, {})
@@ -40,6 +44,9 @@
         except Exception:
             timer(lambda: len(list(cmdutil.walk(repo, pats, {}))))
 
+@command('perfstatus',
+         [('u', 'unknown', False,
+           'ask status to look for unknown files')])
 def perfstatus(ui, repo, **opts):
     #m = match.always(repo.root, repo.getcwd())
     #timer(lambda: sum(map(len, repo.dirstate.status(m, [], False, False,
@@ -55,6 +62,7 @@
         cl._nodecache = {nullid: nullrev}
         cl._nodepos = None
 
+@command('perfheads')
 def perfheads(ui, repo):
     cl = repo.changelog
     def d():
@@ -62,6 +70,7 @@
         clearcaches(cl)
     timer(d)
 
+@command('perftags')
 def perftags(ui, repo):
     import mercurial.changelog, mercurial.manifest
     def t():
@@ -71,6 +80,7 @@
         return len(repo.tags())
     timer(t)
 
+@command('perfancestors')
 def perfancestors(ui, repo):
     heads = repo.changelog.headrevs()
     def d():
@@ -78,6 +88,7 @@
             pass
     timer(d)
 
+@command('perfancestorset')
 def perfancestorset(ui, repo, revset):
     revs = repo.revs(revset)
     heads = repo.changelog.headrevs()
@@ -87,6 +98,7 @@
             rev in s
     timer(d)
 
+@command('perfdirstate')
 def perfdirstate(ui, repo):
     "a" in repo.dirstate
     def d():
@@ -94,6 +106,7 @@
         "a" in repo.dirstate
     timer(d)
 
+@command('perfdirstatedirs')
 def perfdirstatedirs(ui, repo):
     "a" in repo.dirstate
     def d():
@@ -101,6 +114,7 @@
         del repo.dirstate._dirs
     timer(d)
 
+@command('perfdirstatewrite')
 def perfdirstatewrite(ui, repo):
     ds = repo.dirstate
     "a" in ds
@@ -109,6 +123,7 @@
         ds.write()
     timer(d)
 
+@command('perfmanifest')
 def perfmanifest(ui, repo):
     def d():
         t = repo.manifest.tip()
@@ -117,6 +132,7 @@
         repo.manifest._cache = None
     timer(d)
 
+@command('perfchangeset')
 def perfchangeset(ui, repo, rev):
     n = repo[rev].node()
     def d():
@@ -124,6 +140,7 @@
         #repo.changelog._cache = None
     timer(d)
 
+@command('perfindex')
 def perfindex(ui, repo):
     import mercurial.revlog
     mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
@@ -133,12 +150,14 @@
         cl.rev(n)
     timer(d)
 
+@command('perfstartup')
 def perfstartup(ui, repo):
     cmd = sys.argv[0]
     def d():
         os.system("HGRCPATH= %s version -q > /dev/null" % cmd)
     timer(d)
 
+@command('perfparents')
 def perfparents(ui, repo):
     nl = [repo.changelog.node(i) for i in xrange(1000)]
     def d():
@@ -146,13 +165,16 @@
             repo.changelog.parents(n)
     timer(d)
 
+@command('perflookup')
 def perflookup(ui, repo, rev):
     timer(lambda: len(repo.lookup(rev)))
 
+@command('perfrevrange')
 def perfrevrange(ui, repo, *specs):
     revrange = scmutil.revrange
     timer(lambda: len(revrange(repo, specs)))
 
+@command('perfnodelookup')
 def perfnodelookup(ui, repo, rev):
     import mercurial.revlog
     mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
@@ -163,12 +185,15 @@
         clearcaches(cl)
     timer(d)
 
+@command('perflog',
+         [('', 'rename', False, 'ask log to follow renames')])
 def perflog(ui, repo, **opts):
     ui.pushbuffer()
     timer(lambda: commands.log(ui, repo, rev=[], date='', user='',
                                copies=opts.get('rename')))
     ui.popbuffer()
 
+@command('perftemplating')
 def perftemplating(ui, repo):
     ui.pushbuffer()
     timer(lambda: commands.log(ui, repo, rev=[], date='', user='',
@@ -176,15 +201,18 @@
                                ' {author|person}: {desc|firstline}\n'))
     ui.popbuffer()
 
+@command('perfcca')
 def perfcca(ui, repo):
     timer(lambda: scmutil.casecollisionauditor(ui, False, repo.dirstate))
 
+@command('perffncacheload')
 def perffncacheload(ui, repo):
     s = repo.store
     def d():
         s.fncache._load()
     timer(d)
 
+@command('perffncachewrite')
 def perffncachewrite(ui, repo):
     s = repo.store
     s.fncache._load()
@@ -193,6 +221,7 @@
         s.fncache.write()
     timer(d)
 
+@command('perffncacheencode')
 def perffncacheencode(ui, repo):
     s = repo.store
     s.fncache._load()
@@ -201,6 +230,7 @@
             s.encode(p)
     timer(d)
 
+@command('perfdiffwd')
 def perfdiffwd(ui, repo):
     """Profile diff of working directory changes"""
     options = {
@@ -218,6 +248,9 @@
         title = 'diffopts: %s' % (diffopt and ('-' + diffopt) or 'none')
         timer(d, title)
 
+@command('perfrevlog',
+         [('d', 'dist', 100, 'distance between the revisions')],
+         "[INDEXFILE]")
 def perfrevlog(ui, repo, file_, **opts):
     from mercurial import revlog
     dist = opts['dist']
@@ -228,41 +261,8 @@
 
     timer(d)
 
+@command('perfrevset')
 def perfrevset(ui, repo, expr):
     def d():
         repo.revs(expr)
     timer(d)
-
-cmdtable = {
-    'perfcca': (perfcca, []),
-    'perffncacheload': (perffncacheload, []),
-    'perffncachewrite': (perffncachewrite, []),
-    'perffncacheencode': (perffncacheencode, []),
-    'perflookup': (perflookup, []),
-    'perfrevrange': (perfrevrange, []),
-    'perfnodelookup': (perfnodelookup, []),
-    'perfparents': (perfparents, []),
-    'perfstartup': (perfstartup, []),
-    'perfstatus': (perfstatus,
-                   [('u', 'unknown', False,
-                     'ask status to look for unknown files')]),
-    'perfwalk': (perfwalk, []),
-    'perfmanifest': (perfmanifest, []),
-    'perfchangeset': (perfchangeset, []),
-    'perfindex': (perfindex, []),
-    'perfheads': (perfheads, []),
-    'perftags': (perftags, []),
-    'perfancestors': (perfancestors, []),
-    'perfancestorset': (perfancestorset, [], "REVSET"),
-    'perfdirstate': (perfdirstate, []),
-    'perfdirstatedirs': (perfdirstate, []),
-    'perfdirstatewrite': (perfdirstatewrite, []),
-    'perflog': (perflog,
-                [('', 'rename', False, 'ask log to follow renames')]),
-    'perftemplating': (perftemplating, []),
-    'perfdiffwd': (perfdiffwd, []),
-    'perfrevlog': (perfrevlog,
-                   [('d', 'dist', 100, 'distance between the revisions')],
-                   "[INDEXFILE]"),
-    'perfrevset': (perfrevset, [], "REVSET")
-}