blob: 82f85d5fd91ab724e5c3aa6e2f1e65508fa10f79 [file] [log] [blame]
mtklein7ba39cb2014-11-24 12:39:59 -08001#!/usr/bin/env python
2
herbaf4edf92015-07-09 10:50:24 -07003import argparse
4import numpy
mtklein7ba39cb2014-11-24 12:39:59 -08005import sys
6from scipy.stats import mannwhitneyu
herbaf4edf92015-07-09 10:50:24 -07007from scipy.stats import sem
mtklein7ba39cb2014-11-24 12:39:59 -08008
9SIGNIFICANCE_THRESHOLD = 0.0001
10
herbaf4edf92015-07-09 10:50:24 -070011parser = argparse.ArgumentParser(
12 formatter_class=argparse.RawDescriptionHelpFormatter,
13 description='Compare performance of two runs from nanobench.')
14parser.add_argument('--use_means', action='store_true', default=False,
15 help='Use means to calculate performance ratios.')
16parser.add_argument('baseline', help='Baseline file.')
17parser.add_argument('experiment', help='Experiment file.')
18args = parser.parse_args()
19
mtklein7ba39cb2014-11-24 12:39:59 -080020a,b = {},{}
herbaf4edf92015-07-09 10:50:24 -070021for (path, d) in [(args.baseline, a), (args.experiment, b)]:
mtklein7ba39cb2014-11-24 12:39:59 -080022 for line in open(path):
23 try:
cdalton2c56ba52015-06-26 13:32:53 -070024 tokens = line.split()
25 if tokens[0] != "Samples:":
26 continue
27 samples = tokens[1:-1]
28 label = tokens[-1]
mtklein7ba39cb2014-11-24 12:39:59 -080029 d[label] = map(float, samples)
30 except:
31 pass
32
33common = set(a.keys()).intersection(b.keys())
34
35ps = []
36for key in common:
37 _, p = mannwhitneyu(a[key], b[key]) # Non-parametric t-test. Doesn't assume normal dist.
herbaf4edf92015-07-09 10:50:24 -070038 if args.use_means:
39 am, bm = numpy.mean(a[key]), numpy.mean(b[key])
40 asem, bsem = sem(a[key]), sem(b[key])
41 else:
42 am, bm = min(a[key]), min(b[key])
43 asem, bsem = 0, 0
44 ps.append((bm/am, p, key, am, bm, asem, bsem))
mtklein7ba39cb2014-11-24 12:39:59 -080045ps.sort(reverse=True)
46
47def humanize(ns):
48 for threshold, suffix in [(1e9, 's'), (1e6, 'ms'), (1e3, 'us'), (1e0, 'ns')]:
49 if ns > threshold:
50 return "%.3g%s" % (ns/threshold, suffix)
51
52maxlen = max(map(len, common))
53
54# We print only signficant changes in benchmark timing distribution.
55bonferroni = SIGNIFICANCE_THRESHOLD / len(ps) # Adjust for the fact we've run multiple tests.
herbaf4edf92015-07-09 10:50:24 -070056for ratio, p, key, am, bm, asem, bsem in ps:
mtklein7ba39cb2014-11-24 12:39:59 -080057 if p < bonferroni:
Mike Klein8a84db92014-11-24 17:44:23 -050058 str_ratio = ('%.2gx' if ratio < 1 else '%.3gx') % ratio
herbaf4edf92015-07-09 10:50:24 -070059 if args.use_means:
60 print '%*s\t%6s(%6s) -> %6s(%6s)\t%s' % (maxlen, key, humanize(am), humanize(asem),
61 humanize(bm), humanize(bsem), str_ratio)
62 else:
63 print '%*s\t%6s -> %6s\t%s' % (maxlen, key, humanize(am), humanize(bm), str_ratio)