2014-11-24 20:39:59 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2015-07-09 17:50:24 +00:00
|
|
|
import argparse
|
2014-11-24 20:39:59 +00:00
|
|
|
import sys
|
2015-10-28 16:45:44 +00:00
|
|
|
|
|
|
|
have_scipy = True
|
|
|
|
try:
|
|
|
|
import scipy.stats
|
|
|
|
except:
|
|
|
|
have_scipy = False
|
2014-11-24 20:39:59 +00:00
|
|
|
|
|
|
|
SIGNIFICANCE_THRESHOLD = 0.0001
|
|
|
|
|
2015-07-09 17:50:24 +00:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
|
|
description='Compare performance of two runs from nanobench.')
|
|
|
|
parser.add_argument('--use_means', action='store_true', default=False,
|
|
|
|
help='Use means to calculate performance ratios.')
|
|
|
|
parser.add_argument('baseline', help='Baseline file.')
|
|
|
|
parser.add_argument('experiment', help='Experiment file.')
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2014-11-24 20:39:59 +00:00
|
|
|
a,b = {},{}
|
2015-07-09 17:50:24 +00:00
|
|
|
for (path, d) in [(args.baseline, a), (args.experiment, b)]:
|
2014-11-24 20:39:59 +00:00
|
|
|
for line in open(path):
|
|
|
|
try:
|
2015-06-26 20:32:53 +00:00
|
|
|
tokens = line.split()
|
|
|
|
if tokens[0] != "Samples:":
|
|
|
|
continue
|
|
|
|
samples = tokens[1:-1]
|
|
|
|
label = tokens[-1]
|
2014-11-24 20:39:59 +00:00
|
|
|
d[label] = map(float, samples)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
common = set(a.keys()).intersection(b.keys())
|
|
|
|
|
2015-10-28 16:45:44 +00:00
|
|
|
def mean(xs):
|
|
|
|
return sum(xs) / len(xs)
|
|
|
|
|
2014-11-24 20:39:59 +00:00
|
|
|
ps = []
|
|
|
|
for key in common:
|
2015-10-28 16:45:44 +00:00
|
|
|
p, asem, bsem = 0, 0, 0
|
|
|
|
m = mean if args.use_means else min
|
|
|
|
am, bm = m(a[key]), m(b[key])
|
|
|
|
if have_scipy:
|
|
|
|
_, p = scipy.stats.mannwhitneyu(a[key], b[key])
|
2015-11-06 18:35:37 +00:00
|
|
|
asem, bsem = scipy.stats.sem(a[key]), scipy.stats.sem(b[key])
|
2015-07-09 17:50:24 +00:00
|
|
|
ps.append((bm/am, p, key, am, bm, asem, bsem))
|
2014-11-24 20:39:59 +00:00
|
|
|
ps.sort(reverse=True)
|
|
|
|
|
|
|
|
def humanize(ns):
|
|
|
|
for threshold, suffix in [(1e9, 's'), (1e6, 'ms'), (1e3, 'us'), (1e0, 'ns')]:
|
|
|
|
if ns > threshold:
|
|
|
|
return "%.3g%s" % (ns/threshold, suffix)
|
|
|
|
|
|
|
|
maxlen = max(map(len, common))
|
|
|
|
|
|
|
|
# We print only signficant changes in benchmark timing distribution.
|
|
|
|
bonferroni = SIGNIFICANCE_THRESHOLD / len(ps) # Adjust for the fact we've run multiple tests.
|
2015-07-09 17:50:24 +00:00
|
|
|
for ratio, p, key, am, bm, asem, bsem in ps:
|
2014-11-24 20:39:59 +00:00
|
|
|
if p < bonferroni:
|
2014-11-24 22:44:23 +00:00
|
|
|
str_ratio = ('%.2gx' if ratio < 1 else '%.3gx') % ratio
|
2015-07-09 17:50:24 +00:00
|
|
|
if args.use_means:
|
|
|
|
print '%*s\t%6s(%6s) -> %6s(%6s)\t%s' % (maxlen, key, humanize(am), humanize(asem),
|
|
|
|
humanize(bm), humanize(bsem), str_ratio)
|
|
|
|
else:
|
|
|
|
print '%*s\t%6s -> %6s\t%s' % (maxlen, key, humanize(am), humanize(bm), str_ratio)
|