Skip to content

Commit 3844347

Browse files
author
y-p
committed
BLD: test_perf, add -N, run HEAD vbenchmarks multiple times seperately
1 parent 522c112 commit 3844347

File tree

1 file changed

+79
-42
lines changed

1 file changed

+79
-42
lines changed

vb_suite/test_perf.py

Lines changed: 79 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
from suite import REPO_PATH
4343

4444
DEFAULT_MIN_DURATION = 0.01
45-
HEAD_COL="t_head"
45+
HEAD_COL="head[ms]"
46+
BASE_COL="base[ms]"
4647

4748
parser = argparse.ArgumentParser(description='Use vbench to generate a report comparing performance between two commits.')
4849
parser.add_argument('-H', '--head',
@@ -86,6 +87,14 @@
8687
default=3,
8788
type=int,
8889
help='number of times to run each vbench, result value is the average')
90+
parser.add_argument('-N', '--hrepeats',
91+
metavar="N",
92+
dest='hrepeats',
93+
default=1,
94+
type=int,
95+
help='implies -H, number of times to run the vbench suite on the head\n'
96+
'each iteration will yield another column in the output'
97+
)
8998

9099

91100
def get_results_df(db, rev):
@@ -161,70 +170,98 @@ def profile_comparative(benchmarks):
161170
head_res = get_results_df(db, h_head)
162171
baseline_res = get_results_df(db, h_baseline)
163172
ratio = head_res['timing'] / baseline_res['timing']
164-
totals = DataFrame(dict(t_head=head_res['timing'],
165-
t_baseline=baseline_res['timing'],
166-
ratio=ratio,
167-
name=baseline_res.name), columns=[HEAD_COL, "t_baseline", "ratio", "name"])
168-
totals = totals.ix[totals.t_head > args.min_duration]
173+
totals = DataFrame({HEAD_COL:head_res['timing'],
174+
BASE_COL:baseline_res['timing'],
175+
'ratio':ratio,
176+
'name':baseline_res.name},
177+
columns=[HEAD_COL, BASE_COL, "ratio", "name"])
178+
totals = totals.ix[totals[HEAD_COL] > args.min_duration]
169179
# ignore below threshold
170180
totals = totals.dropna(
171181
).sort("ratio").set_index('name') # sort in ascending order
172182

173-
hdr = ftr = """
174-
-----------------------------------------------------------------------
175-
Test name | target[ms] | base[ms] | ratio |
176-
-----------------------------------------------------------------------
177-
""".strip() +"\n"
178-
179-
s = "\n"
180-
s += hdr
181-
for i in range(len(totals)):
182-
t,b,r = totals.irow(i).values
183-
s += "{0:30s} {1: 12.4f} {2: 12.4f} {3: 12.4f}\n".format(totals.index[i],t,b,r)
184-
s+= ftr + "\n"
185-
186-
s += "Ratio < 1.0 means the target commit is faster then the baseline.\n"
187-
s += "Seed used: %d\n\n" % args.seed
188-
189-
s += 'Target [%s] : %s\n' % (h_head, repo.messages.get(h_head, ""))
190-
s += 'Base [%s] : %s\n\n' % (
191-
h_baseline, repo.messages.get(h_baseline, ""))
192-
193-
logfile = open(args.log_file, 'w')
194-
logfile.write(s)
195-
logfile.close()
183+
h_msg = repo.messages.get(h_head, "")
184+
b_msg = repo.messages.get(h_baseline, "")
196185

197-
prprint(s)
198-
prprint("Results were also written to the logfile at '%s'" %
199-
args.log_file)
186+
print_report(totals,h_head=h_head,h_msg=h_msg,
187+
h_baseline=h_baseline,b_msg=b_msg)
200188

201189
if args.outdf:
202190
prprint("The results DataFrame was written to '%s'\n" % args.outdf)
203191
totals.save(args.outdf)
204-
205192
finally:
206193
# print("Disposing of TMP_DIR: %s" % TMP_DIR)
207194
shutil.rmtree(TMP_DIR)
208195

209-
def profile_head(benchmarks):
196+
197+
def profile_head_single(benchmarks):
210198
results = []
211-
s= ""
199+
200+
print( "Running %d benchmarks" % len(benchmarks))
212201
for b in benchmarks:
213202
d = b.run()
214203
d.update(dict(name=b.name))
215204
results.append(dict(name=d['name'],timing=d['timing']))
216-
msg = "{name:<40}: {timing:> 10.4f} [ms]"
217-
line = msg.format(name=results[-1]['name'], timing=results[-1]['timing'])
218-
print(line)
219-
s += line+"\n"
205+
206+
df = DataFrame(results)
207+
df.columns = ["name",HEAD_COL]
208+
return df.set_index("name")[HEAD_COL]
209+
210+
def profile_head(benchmarks):
211+
print( "profile_head")
212+
ss= [profile_head_single(benchmarks) for i in range(args.hrepeats)]
213+
214+
results = DataFrame(ss)
215+
results.index = ["#%d" % i for i in range(len(ss))]
216+
results = results.T
217+
218+
shas, messages, _,_ = _parse_commit_log(None,REPO_PATH,base_commit="HEAD^")
219+
print_report(results,h_head=shas[-1],h_msg=messages[-1])
220+
221+
if args.outdf:
222+
prprint("The results DataFrame was written to '%s'\n" % args.outdf)
223+
DataFrame(results).save(args.outdf)
224+
225+
def print_report(df,h_head=None,h_msg="",h_baseline=None,b_msg=""):
226+
227+
name_width=32
228+
col_width = 12
229+
hdr = ("{:%s}" % name_width).format("Test name")
230+
hdr += ("|{:^%d}" % col_width)* len(df.columns)
231+
hdr += "|"
232+
hdr = hdr.format(*df.columns)
233+
hdr = "-"*len(hdr) + "\n" + hdr + "\n" + "-"*len(hdr) + "\n"
234+
ftr=hdr
235+
s = "\n"
236+
s += hdr
237+
# import ipdb
238+
# ipdb.set_trace()
239+
for i in range(len(df)):
240+
lfmt = ("{:%s}" % name_width)
241+
lfmt += ("| {:%d.4f} " % (col_width-2))* len(df.columns)
242+
lfmt += "|\n"
243+
s += lfmt.format(df.index[i],*list(df.irow(i).values))
244+
245+
s+= ftr + "\n"
246+
247+
s += "Ratio < 1.0 means the target commit is faster then the baseline.\n"
248+
s += "Seed used: %d\n\n" % args.seed
249+
250+
if h_head:
251+
s += 'Target [%s] : %s\n' % (h_head, h_msg)
252+
if h_baseline:
253+
s += 'Base [%s] : %s\n\n' % (
254+
h_baseline, b_msg)
220255

221256
logfile = open(args.log_file, 'w')
222257
logfile.write(s)
223258
logfile.close()
224259

225-
if args.outdf:
226-
prprint("The results DataFrame was written to '%s'\n" % args.outdf)
227-
DataFrame(results,columns=["name",HEAD_COL]).save(args.outdf)
260+
prprint(s)
261+
prprint("Results were also written to the logfile at '%s'" %
262+
args.log_file)
263+
264+
228265

229266
def main():
230267
from suite import benchmarks

0 commit comments

Comments
 (0)