contrib/perf.py
changeset 39822 86dbeb7c9a11
parent 39821 6787dc1b93a9
child 39823 c4ab9fa81377
equal deleted inserted replaced
39821:6787dc1b93a9 39822:86dbeb7c9a11
    66     pass
    66     pass
    67 try:
    67 try:
    68     from mercurial import pycompat
    68     from mercurial import pycompat
    69     getargspec = pycompat.getargspec  # added to module after 4.5
    69     getargspec = pycompat.getargspec  # added to module after 4.5
    70     _sysstr = pycompat.sysstr         # since 4.0 (or 2219f4f82ede)
    70     _sysstr = pycompat.sysstr         # since 4.0 (or 2219f4f82ede)
       
    71     _xrange = pycompat.xrange         # since 4.8 (or 7eba8f83129b)
    71 except (ImportError, AttributeError):
    72 except (ImportError, AttributeError):
    72     import inspect
    73     import inspect
    73     getargspec = inspect.getargspec
    74     getargspec = inspect.getargspec
    74     _sysstr = lambda x: x             # no py3 support
    75     _sysstr = lambda x: x             # no py3 support
       
    76     _xrange = xrange
    75 
    77 
    76 try:
    78 try:
    77     # 4.7+
    79     # 4.7+
    78     queue = pycompat.queue.Queue
    80     queue = pycompat.queue.Queue
    79 except (AttributeError, ImportError):
    81 except (AttributeError, ImportError):
   929     # experimental config: perf.parentscount
   931     # experimental config: perf.parentscount
   930     count = getint(ui, b"perf", b"parentscount", 1000)
   932     count = getint(ui, b"perf", b"parentscount", 1000)
   931     if len(repo.changelog) < count:
   933     if len(repo.changelog) < count:
   932         raise error.Abort(b"repo needs %d commits for this test" % count)
   934         raise error.Abort(b"repo needs %d commits for this test" % count)
   933     repo = repo.unfiltered()
   935     repo = repo.unfiltered()
   934     nl = [repo.changelog.node(i) for i in xrange(count)]
   936     nl = [repo.changelog.node(i) for i in _xrange(count)]
   935     def d():
   937     def d():
   936         for n in nl:
   938         for n in nl:
   937             repo.changelog.parents(n)
   939             repo.changelog.parents(n)
   938     timer(d)
   940     timer(d)
   939     fm.end()
   941     fm.end()
   976     maxb1 = 100000
   978     maxb1 = 100000
   977     random.seed(0)
   979     random.seed(0)
   978     randint = random.randint
   980     randint = random.randint
   979     currentlines = 0
   981     currentlines = 0
   980     arglist = []
   982     arglist = []
   981     for rev in xrange(edits):
   983     for rev in _xrange(edits):
   982         a1 = randint(0, currentlines)
   984         a1 = randint(0, currentlines)
   983         a2 = randint(a1, min(currentlines, a1 + maxhunklines))
   985         a2 = randint(a1, min(currentlines, a1 + maxhunklines))
   984         b1 = randint(0, maxb1)
   986         b1 = randint(0, maxb1)
   985         b2 = randint(b1, b1 + maxhunklines)
   987         b2 = randint(b1, b1 + maxhunklines)
   986         currentlines += (b2 - b1) - (a2 - a1)
   988         currentlines += (b2 - b1) - (a2 - a1)
  1214                     mdiff.bdiff.blocks(*pair)
  1216                     mdiff.bdiff.blocks(*pair)
  1215                 else:
  1217                 else:
  1216                     mdiff.textdiff(*pair)
  1218                     mdiff.textdiff(*pair)
  1217     else:
  1219     else:
  1218         q = queue()
  1220         q = queue()
  1219         for i in xrange(threads):
  1221         for i in _xrange(threads):
  1220             q.put(None)
  1222             q.put(None)
  1221         ready = threading.Condition()
  1223         ready = threading.Condition()
  1222         done = threading.Event()
  1224         done = threading.Event()
  1223         for i in xrange(threads):
  1225         for i in _xrange(threads):
  1224             threading.Thread(target=_bdiffworker,
  1226             threading.Thread(target=_bdiffworker,
  1225                              args=(q, blocks, xdiff, ready, done)).start()
  1227                              args=(q, blocks, xdiff, ready, done)).start()
  1226         q.join()
  1228         q.join()
  1227         def d():
  1229         def d():
  1228             for pair in textpairs:
  1230             for pair in textpairs:
  1229                 q.put(pair)
  1231                 q.put(pair)
  1230             for i in xrange(threads):
  1232             for i in _xrange(threads):
  1231                 q.put(None)
  1233                 q.put(None)
  1232             with ready:
  1234             with ready:
  1233                 ready.notify_all()
  1235                 ready.notify_all()
  1234             q.join()
  1236             q.join()
  1235     timer, fm = gettimer(ui, opts)
  1237     timer, fm = gettimer(ui, opts)
  1236     timer(d)
  1238     timer(d)
  1237     fm.end()
  1239     fm.end()
  1238 
  1240 
  1239     if withthreads:
  1241     if withthreads:
  1240         done.set()
  1242         done.set()
  1241         for i in xrange(threads):
  1243         for i in _xrange(threads):
  1242             q.put(None)
  1244             q.put(None)
  1243         with ready:
  1245         with ready:
  1244             ready.notify_all()
  1246             ready.notify_all()
  1245 
  1247 
  1246 @command(b'perfunidiff', revlogopts + formatteropts + [
  1248 @command(b'perfunidiff', revlogopts + formatteropts + [
  1470 
  1472 
  1471         if reverse:
  1473         if reverse:
  1472             beginrev, endrev = endrev, beginrev
  1474             beginrev, endrev = endrev, beginrev
  1473             dist = -1 * dist
  1475             dist = -1 * dist
  1474 
  1476 
  1475         for x in xrange(beginrev, endrev, dist):
  1477         for x in _xrange(beginrev, endrev, dist):
  1476             # Old revisions don't support passing int.
  1478             # Old revisions don't support passing int.
  1477             n = rl.node(x)
  1479             n = rl.node(x)
  1478             rl.revision(n)
  1480             rl.revision(n)
  1479 
  1481 
  1480     timer, fm = gettimer(ui, opts)
  1482     timer, fm = gettimer(ui, opts)
  1883      (b'', b'mixedgetfreq', 50, b'frequency of get vs set ops in mixed mode')],
  1885      (b'', b'mixedgetfreq', 50, b'frequency of get vs set ops in mixed mode')],
  1884     norepo=True)
  1886     norepo=True)
  1885 def perflrucache(ui, mincost=0, maxcost=100, costlimit=0, size=4,
  1887 def perflrucache(ui, mincost=0, maxcost=100, costlimit=0, size=4,
  1886                  gets=10000, sets=10000, mixed=10000, mixedgetfreq=50, **opts):
  1888                  gets=10000, sets=10000, mixed=10000, mixedgetfreq=50, **opts):
  1887     def doinit():
  1889     def doinit():
  1888         for i in xrange(10000):
  1890         for i in _xrange(10000):
  1889             util.lrucachedict(size)
  1891             util.lrucachedict(size)
  1890 
  1892 
  1891     costrange = list(range(mincost, maxcost + 1))
  1893     costrange = list(range(mincost, maxcost + 1))
  1892 
  1894 
  1893     values = []
  1895     values = []
  1894     for i in xrange(size):
  1896     for i in _xrange(size):
  1895         values.append(random.randint(0, sys.maxint))
  1897         values.append(random.randint(0, sys.maxint))
  1896 
  1898 
  1897     # Get mode fills the cache and tests raw lookup performance with no
  1899     # Get mode fills the cache and tests raw lookup performance with no
  1898     # eviction.
  1900     # eviction.
  1899     getseq = []
  1901     getseq = []
  1900     for i in xrange(gets):
  1902     for i in _xrange(gets):
  1901         getseq.append(random.choice(values))
  1903         getseq.append(random.choice(values))
  1902 
  1904 
  1903     def dogets():
  1905     def dogets():
  1904         d = util.lrucachedict(size)
  1906         d = util.lrucachedict(size)
  1905         for v in values:
  1907         for v in values:
  1920                 pass
  1922                 pass
  1921 
  1923 
  1922     # Set mode tests insertion speed with cache eviction.
  1924     # Set mode tests insertion speed with cache eviction.
  1923     setseq = []
  1925     setseq = []
  1924     costs = []
  1926     costs = []
  1925     for i in xrange(sets):
  1927     for i in _xrange(sets):
  1926         setseq.append(random.randint(0, sys.maxint))
  1928         setseq.append(random.randint(0, sys.maxint))
  1927         costs.append(random.choice(costrange))
  1929         costs.append(random.choice(costrange))
  1928 
  1930 
  1929     def doinserts():
  1931     def doinserts():
  1930         d = util.lrucachedict(size)
  1932         d = util.lrucachedict(size)
  1941         for v in setseq:
  1943         for v in setseq:
  1942             d[v] = v
  1944             d[v] = v
  1943 
  1945 
  1944     # Mixed mode randomly performs gets and sets with eviction.
  1946     # Mixed mode randomly performs gets and sets with eviction.
  1945     mixedops = []
  1947     mixedops = []
  1946     for i in xrange(mixed):
  1948     for i in _xrange(mixed):
  1947         r = random.randint(0, 100)
  1949         r = random.randint(0, 100)
  1948         if r < mixedgetfreq:
  1950         if r < mixedgetfreq:
  1949             op = 0
  1951             op = 0
  1950         else:
  1952         else:
  1951             op = 1
  1953             op = 1