Skip to content

Commit 07163ac

Browse files
author
y-p
committed
BLD: test_perf, add burn-in, warn if 'affinity' missing, transpose running order in --head
1 parent b5840b3 commit 07163ac

File tree

1 file changed

+41
-22
lines changed

1 file changed

+41
-22
lines changed

vb_suite/test_perf.py

+41-22
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import random
3838
import numpy as np
3939

40-
from pandas import DataFrame
40+
from pandas import DataFrame, Series
4141

4242
from suite import REPO_PATH
4343

@@ -102,14 +102,18 @@
102102
'each iteration will yield another column in the output'
103103
)
104104
parser.add_argument('-a', '--affinity',
105-
metavar="b",
105+
metavar="a",
106106
dest='affinity',
107107
default=1,
108108
type=int,
109109
help='set processor affinity of processm by default bind to cpu/core #1 only'
110110
'requires the "affinity" python module , will raise Warning otherwise' )
111-
112-
111+
parser.add_argument('-u', '--burnin',
112+
metavar="u",
113+
dest='burnin',
114+
default=1,
115+
type=int,
116+
help='number of extra iteration per benchmark to perform first, then throw away. ' )
113117

114118
def get_results_df(db, rev):
115119
"""Takes a git commit hash and returns a Dataframe of benchmark results
@@ -220,42 +224,53 @@ def profile_comparative(benchmarks):
220224
shutil.rmtree(TMP_DIR)
221225

222226

223-
def profile_head_single(benchmarks):
227+
def profile_head_single(benchmark):
224228
results = []
225229

226-
print( "Running %d benchmarks" % len(benchmarks))
227-
for b in benchmarks:
230+
231+
N = args.hrepeats + args.burnin
232+
233+
results = []
234+
for i in range(N):
228235
clear()
229236
d=dict()
230-
sys.stdout.write('.')
231-
sys.stdout.flush()
232237
try:
233-
d = b.run()
238+
d = benchmark.run()
239+
234240
except KeyboardInterrupt:
235241
raise
236242
except Exception as e: # if a single vbench bursts into flames, don't die.
237243
err=""
238244
try:
239-
err = d.get("traceback","")
245+
err = d.get("traceback")
246+
if err is None:
247+
err = str(e)
240248
except:
241249
pass
242-
print("%s died with:\n%s\nSkipping...\n" % (b.name, err))
250+
print("%s died with:\n%s\nSkipping...\n" % (benchmark.name, err))
251+
252+
results.append(d.get('timing',np.nan))
243253

244-
d.update(dict(name=b.name))
245-
results.append(dict(name=b.name,timing=d.get('timing',np.nan)))
254+
if results:
255+
# throw away the burn_in
256+
results = results[args.burnin:]
257+
sys.stdout.write('.')
258+
sys.stdout.flush()
259+
return Series(results, name=benchmark.name)
246260

247-
print("\n\n")
248-
df = DataFrame(results)
249-
df.columns = ["name",HEAD_COL]
250-
return df.set_index("name")[HEAD_COL]
261+
# df = DataFrame(results)
262+
# df.columns = ["name",HEAD_COL]
263+
# return df.set_index("name")[HEAD_COL]
251264

252265
def profile_head(benchmarks):
266+
print( "Performing %d benchmarks (%d runs each)" % ( len(benchmarks), args.hrepeats))
253267

254-
ss= [profile_head_single(benchmarks) for i in range(args.hrepeats)]
268+
ss= [profile_head_single(b) for b in benchmarks]
255269

256270
results = DataFrame(ss)
257-
results.index = ["#%d" % i for i in range(len(ss))]
258-
results = results.T
271+
results.columns=[ "#%d" %i for i in range(args.hrepeats)]
272+
# results.index = ["#%d" % i for i in range(len(ss))]
273+
# results = results.T
259274

260275
shas, messages, _,_ = _parse_commit_log(None,REPO_PATH,base_commit="HEAD^")
261276
print_report(results,h_head=shas[-1],h_msg=messages[-1])
@@ -342,7 +357,11 @@ def main():
342357
print("CPU affinity set to %d" % args.affinity)
343358
except ImportError:
344359
import warnings
345-
warnings.warn("The 'affinity' module is not available, results may be unreliable")
360+
print("\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"+
361+
"The 'affinity' module is not available, results may be unreliable\n" +
362+
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n"
363+
)
364+
time.sleep(2)
346365

347366
print("\n")
348367
prprint("LOG_FILE = %s" % args.log_file)

0 commit comments

Comments
 (0)