comparison contrib/benchmarks/__init__.py @ 43076:2372284d9457

formatting: blacken the codebase This is using my patch to black (https://github.com/psf/black/pull/826) so we don't un-wrap collection literals. Done with: hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S # skip-blame mass-reformatting only # no-check-commit reformats foo_bar functions Differential Revision: https://phab.mercurial-scm.org/D6971
author Augie Fackler <augie@google.com>
date Sun, 06 Oct 2019 09:45:02 -0400
parents be0e7af80543
children 9d2b2df2c2ba
comparison
equal deleted inserted replaced
43075:57875cf423c9 43076:2372284d9457
42 hg, 42 hg,
43 ui as uimod, 43 ui as uimod,
44 util, 44 util,
45 ) 45 )
46 46
47 basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), 47 basedir = os.path.abspath(
48 os.path.pardir, os.path.pardir)) 48 os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir)
49 )
49 reposdir = os.environ['REPOS_DIR'] 50 reposdir = os.environ['REPOS_DIR']
50 reposnames = [name for name in os.listdir(reposdir) 51 reposnames = [
51 if os.path.isdir(os.path.join(reposdir, name, ".hg"))] 52 name
53 for name in os.listdir(reposdir)
54 if os.path.isdir(os.path.join(reposdir, name, ".hg"))
55 ]
52 if not reposnames: 56 if not reposnames:
53 raise ValueError("No repositories found in $REPO_DIR") 57 raise ValueError("No repositories found in $REPO_DIR")
54 outputre = re.compile((r'! wall (\d+.\d+) comb \d+.\d+ user \d+.\d+ sys ' 58 outputre = re.compile(
55 r'\d+.\d+ \(best of \d+\)')) 59 (
60 r'! wall (\d+.\d+) comb \d+.\d+ user \d+.\d+ sys '
61 r'\d+.\d+ \(best of \d+\)'
62 )
63 )
64
56 65
57 def runperfcommand(reponame, command, *args, **kwargs): 66 def runperfcommand(reponame, command, *args, **kwargs):
58 os.environ["HGRCPATH"] = os.environ.get("ASVHGRCPATH", "") 67 os.environ["HGRCPATH"] = os.environ.get("ASVHGRCPATH", "")
59 # for "historical portability" 68 # for "historical portability"
60 # ui.load() has been available since d83ca85 69 # ui.load() has been available since d83ca85
61 if util.safehasattr(uimod.ui, "load"): 70 if util.safehasattr(uimod.ui, "load"):
62 ui = uimod.ui.load() 71 ui = uimod.ui.load()
63 else: 72 else:
64 ui = uimod.ui() 73 ui = uimod.ui()
65 repo = hg.repository(ui, os.path.join(reposdir, reponame)) 74 repo = hg.repository(ui, os.path.join(reposdir, reponame))
66 perfext = extensions.load(ui, 'perfext', 75 perfext = extensions.load(
67 os.path.join(basedir, 'contrib', 'perf.py')) 76 ui, 'perfext', os.path.join(basedir, 'contrib', 'perf.py')
77 )
68 cmd = getattr(perfext, command) 78 cmd = getattr(perfext, command)
69 ui.pushbuffer() 79 ui.pushbuffer()
70 cmd(ui, repo, *args, **kwargs) 80 cmd(ui, repo, *args, **kwargs)
71 output = ui.popbuffer() 81 output = ui.popbuffer()
72 match = outputre.search(output) 82 match = outputre.search(output)
73 if not match: 83 if not match:
74 raise ValueError("Invalid output {0}".format(output)) 84 raise ValueError("Invalid output {0}".format(output))
75 return float(match.group(1)) 85 return float(match.group(1))
86
76 87
77 def perfbench(repos=reposnames, name=None, params=None): 88 def perfbench(repos=reposnames, name=None, params=None):
78 """decorator to declare ASV benchmark based on contrib/perf.py extension 89 """decorator to declare ASV benchmark based on contrib/perf.py extension
79 90
80 An ASV benchmark is a python function with the given attributes: 91 An ASV benchmark is a python function with the given attributes:
102 def decorator(func): 113 def decorator(func):
103 @functools.wraps(func) 114 @functools.wraps(func)
104 def wrapped(repo, *args): 115 def wrapped(repo, *args):
105 def perf(command, *a, **kw): 116 def perf(command, *a, **kw):
106 return runperfcommand(repo, command, *a, **kw) 117 return runperfcommand(repo, command, *a, **kw)
118
107 return func(perf, *args) 119 return func(perf, *args)
108 120
109 wrapped.params = [p[1] for p in params] 121 wrapped.params = [p[1] for p in params]
110 wrapped.param_names = [p[0] for p in params] 122 wrapped.param_names = [p[0] for p in params]
111 wrapped.pretty_name = name 123 wrapped.pretty_name = name
112 return wrapped 124 return wrapped
125
113 return decorator 126 return decorator