comparison contrib/perf.py @ 40214:b456b2e0ad9f

py3: make test-contrib-perf.t work on python 3 Differential Revision: https://phab.mercurial-scm.org/D5025
author Pulkit Goyal <pulkit@yandex-team.ru>
date Sat, 13 Oct 2018 03:46:57 +0300
parents 21261fc0fb2b
children fa88170c10bb
comparison
equal deleted inserted replaced
40213:83912321bf09 40214:b456b2e0ad9f
73 from mercurial import pycompat 73 from mercurial import pycompat
74 getargspec = pycompat.getargspec # added to module after 4.5 74 getargspec = pycompat.getargspec # added to module after 4.5
75 _byteskwargs = pycompat.byteskwargs # since 4.1 (or fbc3f73dc802) 75 _byteskwargs = pycompat.byteskwargs # since 4.1 (or fbc3f73dc802)
76 _sysstr = pycompat.sysstr # since 4.0 (or 2219f4f82ede) 76 _sysstr = pycompat.sysstr # since 4.0 (or 2219f4f82ede)
77 _xrange = pycompat.xrange # since 4.8 (or 7eba8f83129b) 77 _xrange = pycompat.xrange # since 4.8 (or 7eba8f83129b)
78 fsencode = pycompat.fsencode # since 3.9 (or f4a5e0e86a7e)
78 if pycompat.ispy3: 79 if pycompat.ispy3:
79 _maxint = sys.maxsize # per py3 docs for replacing maxint 80 _maxint = sys.maxsize # per py3 docs for replacing maxint
80 else: 81 else:
81 _maxint = sys.maxint 82 _maxint = sys.maxint
82 except (ImportError, AttributeError): 83 except (ImportError, AttributeError):
83 import inspect 84 import inspect
84 getargspec = inspect.getargspec 85 getargspec = inspect.getargspec
85 _byteskwargs = identity 86 _byteskwargs = identity
87 fsencode = identity # no py3 support
86 _maxint = sys.maxint # no py3 support 88 _maxint = sys.maxint # no py3 support
87 _sysstr = lambda x: x # no py3 support 89 _sysstr = lambda x: x # no py3 support
88 _xrange = xrange 90 _xrange = xrange
89 91
90 try: 92 try:
966 968
967 @command(b'perfstartup', formatteropts) 969 @command(b'perfstartup', formatteropts)
968 def perfstartup(ui, repo, **opts): 970 def perfstartup(ui, repo, **opts):
969 opts = _byteskwargs(opts) 971 opts = _byteskwargs(opts)
970 timer, fm = gettimer(ui, opts) 972 timer, fm = gettimer(ui, opts)
971 cmd = sys.argv[0] 973 cmd = fsencode(sys.argv[0])
972 def d(): 974 def d():
973 if os.name != r'nt': 975 if os.name != r'nt':
974 os.system(b"HGRCPATH= %s version -q > /dev/null" % cmd) 976 os.system(b"HGRCPATH= %s version -q > /dev/null" % cmd)
975 else: 977 else:
976 os.environ[r'HGRCPATH'] = r' ' 978 os.environ[r'HGRCPATH'] = r' '
1385 def perfdiffwd(ui, repo, **opts): 1387 def perfdiffwd(ui, repo, **opts):
1386 """Profile diff of working directory changes""" 1388 """Profile diff of working directory changes"""
1387 opts = _byteskwargs(opts) 1389 opts = _byteskwargs(opts)
1388 timer, fm = gettimer(ui, opts) 1390 timer, fm = gettimer(ui, opts)
1389 options = { 1391 options = {
1390 b'w': b'ignore_all_space', 1392 'w': 'ignore_all_space',
1391 b'b': b'ignore_space_change', 1393 'b': 'ignore_space_change',
1392 b'B': b'ignore_blank_lines', 1394 'B': 'ignore_blank_lines',
1393 } 1395 }
1394 1396
1395 for diffopt in (b'', b'w', b'b', b'B', b'wB'): 1397 for diffopt in ('', 'w', 'b', 'B', 'wB'):
1396 opts = dict((options[c], b'1') for c in diffopt) 1398 opts = dict((options[c], b'1') for c in diffopt)
1397 def d(): 1399 def d():
1398 ui.pushbuffer() 1400 ui.pushbuffer()
1399 commands.diff(ui, repo, **opts) 1401 commands.diff(ui, repo, **opts)
1400 ui.popbuffer() 1402 ui.popbuffer()
1403 diffopt = diffopt.encode('ascii')
1401 title = b'diffopts: %s' % (diffopt and (b'-' + diffopt) or b'none') 1404 title = b'diffopts: %s' % (diffopt and (b'-' + diffopt) or b'none')
1402 timer(d, title) 1405 timer(d, title)
1403 fm.end() 1406 fm.end()
1404 1407
1405 @command(b'perfrevlogindex', revlogopts + formatteropts, 1408 @command(b'perfrevlogindex', revlogopts + formatteropts,
1771 1774
1772 chain = r._deltachain(rev)[0] 1775 chain = r._deltachain(rev)[0]
1773 data = segmentforrevs(chain[0], chain[-1])[1] 1776 data = segmentforrevs(chain[0], chain[-1])[1]
1774 rawchunks = getrawchunks(data, chain) 1777 rawchunks = getrawchunks(data, chain)
1775 bins = r._chunks(chain) 1778 bins = r._chunks(chain)
1776 text = str(bins[0]) 1779 text = bytes(bins[0])
1777 bins = bins[1:] 1780 bins = bins[1:]
1778 text = mdiff.patches(text, bins) 1781 text = mdiff.patches(text, bins)
1779 1782
1780 benches = [ 1783 benches = [
1781 (lambda: dorevision(), b'full'), 1784 (lambda: dorevision(), b'full'),