Skip to content

Commit a8ed983

Browse files
author
y-p
committed
BLD: move perf_HEAD functionality into test_perf. -H arg
1 parent 6cda5dc commit a8ed983

File tree

1 file changed

+73
-41
lines changed

1 file changed

+73
-41
lines changed

vb_suite/test_perf.py

Lines changed: 73 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,17 @@
3737
import random
3838
import numpy as np
3939

40+
from pandas import DataFrame
41+
42+
from suite import REPO_PATH
43+
4044
DEFAULT_MIN_DURATION = 0.01
45+
HEAD_COL="t_head"
4146

4247
parser = argparse.ArgumentParser(description='Use vbench to generate a report comparing performance between two commits.')
43-
parser.add_argument('-a', '--auto',
44-
help='Execute a run using the defaults for the base and target commits.',
48+
parser.add_argument('-H', '--head',
49+
help='Execute vbenches using the currently checked out copy.',
50+
dest='head',
4551
action='store_true',
4652
default=False)
4753
parser.add_argument('-b', '--base-commit',
@@ -77,7 +83,6 @@
7783

7884

7985
def get_results_df(db, rev):
80-
from pandas import DataFrame
8186
"""Takes a git commit hash and returns a Dataframe of benchmark results
8287
"""
8388
bench = DataFrame(db.get_benchmarks())
@@ -93,47 +98,16 @@ def get_results_df(db, rev):
9398
def prprint(s):
9499
print("*** %s" % s)
95100

96-
def main():
97-
from pandas import DataFrame
101+
def profile_comparative(benchmarks):
102+
98103
from vbench.api import BenchmarkRunner
99104
from vbench.db import BenchmarkDB
100105
from vbench.git import GitRepo
101-
from suite import REPO_PATH, BUILD, DB_PATH, PREPARE, dependencies, benchmarks
102-
103-
# GitRepo wants exactly 7 character hash?
104-
args.base_commit = args.base_commit[:7]
105-
if args.target_commit:
106-
args.target_commit = args.target_commit[:7]
107-
108-
if not args.log_file:
109-
args.log_file = os.path.abspath(
110-
os.path.join(REPO_PATH, 'vb_suite.log'))
111-
112-
if args.outdf:
113-
# not bullet-proof but enough for us
114-
if os.path.sep not in args.outdf:
115-
args.outdf = os.path.join(os.curdir, args.outdf)
116-
117-
if args.log_file:
118-
# not bullet-proof but enough for us
119-
if os.path.sep not in args.log_file:
120-
args.log_file = os.path.join(os.curdir, args.log_file)
121-
122-
random.seed(args.seed)
123-
np.random.seed(args.seed)
124-
106+
from suite import BUILD, DB_PATH, PREPARE, dependencies
125107
TMP_DIR = tempfile.mkdtemp()
126-
prprint("TMP_DIR = %s" % TMP_DIR)
127-
prprint("LOG_FILE = %s\n" % args.log_file)
128-
129-
saved_dir = os.path.curdir
130-
# move away from the pandas root dit, to avoid possible import
131-
# surprises
132-
os.chdir(os.path.dirname(os.path.abspath(__file__)))
133-
134-
benchmarks = [x for x in benchmarks if re.search(args.regex,x.name)]
135108

136109
try:
110+
137111
prprint("Opening DB at '%s'...\n" % DB_PATH)
138112
db = BenchmarkDB(DB_PATH)
139113

@@ -184,7 +158,7 @@ def main():
184158
totals = DataFrame(dict(t_head=head_res['timing'],
185159
t_baseline=baseline_res['timing'],
186160
ratio=ratio,
187-
name=baseline_res.name), columns=["t_head", "t_baseline", "ratio", "name"])
161+
name=baseline_res.name), columns=[HEAD_COL, "t_baseline", "ratio", "name"])
188162
totals = totals.ix[totals.t_head > args.min_duration]
189163
# ignore below threshold
190164
totals = totals.dropna(
@@ -225,9 +199,67 @@ def main():
225199
finally:
226200
# print("Disposing of TMP_DIR: %s" % TMP_DIR)
227201
shutil.rmtree(TMP_DIR)
228-
os.chdir(saved_dir)
229202

203+
def profile_head(benchmarks):
204+
results = []
205+
s= ""
206+
for b in benchmarks:
207+
d = b.run()
208+
d.update(dict(name=b.name))
209+
results.append(dict(name=d['name'],timing=d['timing']))
210+
msg = "{name:<40}: {timing:> 10.4f} [ms]"
211+
line = msg.format(name=results[-1]['name'], timing=results[-1]['timing'])
212+
print(line)
213+
s += line+"\n"
214+
215+
logfile = open(args.log_file, 'w')
216+
logfile.write(s)
217+
logfile.close()
218+
219+
if args.outdf:
220+
prprint("The results DataFrame was written to '%s'\n" % args.outdf)
221+
DataFrame(results,columns=["name",HEAD_COL]).save(args.outdf)
222+
223+
def main():
224+
from suite import benchmarks
225+
# GitRepo wants exactly 7 character hash?
226+
if args.base_commit:
227+
args.base_commit = args.base_commit[:7]
228+
if args.target_commit:
229+
args.target_commit = args.target_commit[:7]
230+
231+
if not args.log_file:
232+
args.log_file = os.path.abspath(
233+
os.path.join(REPO_PATH, 'vb_suite.log'))
234+
235+
if args.outdf:
236+
# not bullet-proof but enough for us
237+
if os.path.sep not in args.outdf:
238+
args.outdf = os.path.join(os.curdir, args.outdf)
239+
240+
if args.log_file:
241+
# not bullet-proof but enough for us
242+
if os.path.sep not in args.log_file:
243+
args.log_file = os.path.join(os.curdir, args.log_file)
244+
245+
random.seed(args.seed)
246+
np.random.seed(args.seed)
247+
248+
prprint("LOG_FILE = %s\n" % args.log_file)
249+
250+
saved_dir = os.path.curdir
251+
# move away from the pandas root dit, to avoid possible import
252+
# surprises
253+
os.chdir(os.path.dirname(os.path.abspath(__file__)))
254+
255+
benchmarks = [x for x in benchmarks if re.search(args.regex,x.name)]
256+
257+
if args.head:
258+
profile_head(benchmarks)
259+
else:
260+
profile_comparative(benchmarks)
230261

262+
os.chdir(saved_dir)
231263

232264
# hack , vbench.git ignores some commits, but we
233265
# need to be able to reference any commit.
@@ -279,7 +311,7 @@ def inner(repo_path):
279311

280312
if __name__ == '__main__':
281313
args = parser.parse_args()
282-
if not args.auto and (not args.base_commit and not args.target_commit):
314+
if not args.head and (not args.base_commit and not args.target_commit):
283315
parser.print_help()
284316
else:
285317
main()

0 commit comments

Comments
 (0)