contrib/perf.py
changeset 38969 1601afbb573c
parent 38781 0a57945aaf7f
child 38977 a1f694779b2f
equal deleted inserted replaced
38968:c10be3fc200b 38969:1601afbb573c
   887 def perflookup(ui, repo, rev, **opts):
   887 def perflookup(ui, repo, rev, **opts):
   888     timer, fm = gettimer(ui, opts)
   888     timer, fm = gettimer(ui, opts)
   889     timer(lambda: len(repo.lookup(rev)))
   889     timer(lambda: len(repo.lookup(rev)))
   890     fm.end()
   890     fm.end()
   891 
   891 
       
   892 @command('perflinelogedits',
       
   893          [('n', 'edits', 10000, 'number of edits'),
       
   894           ('', 'max-hunk-lines', 10, 'max lines in a hunk'),
       
   895          ], norepo=True)
       
   896 def perflinelogedits(ui, **opts):
       
   897     from mercurial import linelog
       
   898 
       
   899     edits = opts['edits']
       
   900     maxhunklines = opts['max_hunk_lines']
       
   901 
       
   902     maxb1 = 100000
       
   903     random.seed(0)
       
   904     randint = random.randint
       
   905     currentlines = 0
       
   906     arglist = []
       
   907     for rev in xrange(edits):
       
   908         a1 = randint(0, currentlines)
       
   909         a2 = randint(a1, min(currentlines, a1 + maxhunklines))
       
   910         b1 = randint(0, maxb1)
       
   911         b2 = randint(b1, b1 + maxhunklines)
       
   912         currentlines += (b2 - b1) - (a2 - a1)
       
   913         arglist.append((rev, a1, a2, b1, b2))
       
   914 
       
   915     def d():
       
   916         ll = linelog.linelog()
       
   917         for args in arglist:
       
   918             ll.replacelines(*args)
       
   919 
       
   920     timer, fm = gettimer(ui, opts)
       
   921     timer(d)
       
   922     fm.end()
       
   923 
   892 @command('perfrevrange', formatteropts)
   924 @command('perfrevrange', formatteropts)
   893 def perfrevrange(ui, repo, *specs, **opts):
   925 def perfrevrange(ui, repo, *specs, **opts):
   894     timer, fm = gettimer(ui, opts)
   926     timer, fm = gettimer(ui, opts)
   895     revrange = scmutil.revrange
   927     revrange = scmutil.revrange
   896     timer(lambda: len(revrange(repo, specs)))
   928     timer(lambda: len(revrange(repo, specs)))