Skip to content

Commit 48e8970

Browse files
committed
allow comparision between branches (and commits)
1 parent 545dde6 commit 48e8970

2 files changed

Lines changed: 87 additions & 0 deletions

File tree

benchmark/compare.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import argparse
2+
import pickle
3+
import numpy
4+
from scipy.stats import linregress
5+
6+
parser = argparse.ArgumentParser(description='Compare two benchmarks.',
7+
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
8+
parser.add_argument('left', help='First input for comparison')
9+
parser.add_argument('right', help='Second input for comparison')
10+
args = parser.parse_args()
11+
12+
13+
with open(args.left, "rb") as f:
14+
left = pickle.load(f)
15+
16+
with open(args.right, "rb") as f:
17+
right = pickle.load(f)
18+
19+
if left.keys()!=right.keys():
20+
raise ValueError("Different Experiments")
21+
22+
experiment = right.keys()
23+
24+
for exp in experiment:
25+
print("\nExperiment: {}".format(exp))
26+
if left[exp].keys()!=right[exp].keys():
27+
raise ValueError("Different Instrumenters")
28+
instrumenters = left[exp].keys()
29+
30+
for inst in instrumenters:
31+
print("\n\tInstrumenter: {}".format(inst))
32+
if left[exp][inst].keys()!=right[exp][inst].keys():
33+
raise ValueError("Different Iterations")
34+
iterations = left[exp][inst].keys()
35+
Y_left = []
36+
Y_right = []
37+
X = []
38+
for it in iterations:
39+
left_val = left[exp][inst][it]
40+
right_val = right[exp][inst][it]
41+
if len(left_val)!=len(right_val):
42+
raise ValueError("Different Repetitons")
43+
44+
Y_left.append(left_val)
45+
Y_right.append(right_val)
46+
X.append(numpy.full([len(left_val)], it))
47+
48+
print("\t\tInterations {}".format(it))
49+
print("\t\tMean: {:>7.4f} s {:>7.4f} s".format(numpy.mean(left_val), numpy.mean(right_val)))
50+
print("\t\tMedian: {:>7.4f} s {:>7.4f} s".format(numpy.quantile(left_val, 0.50), numpy.quantile(right_val, 0.50)))
51+
print("\t\t5%: {:>7.4f} s {:>7.4f} s".format(numpy.quantile(left_val, 0.05), numpy.quantile(right_val, 0.05)))
52+
print("\t\t95%: {:>7.4f} s {:>7.4f} s".format(numpy.quantile(left_val, 0.95), numpy.quantile(right_val, 0.95)))
53+
Y_left = numpy.asarray(Y_left,dtype=float).flatten()
54+
Y_right = numpy.asarray(Y_right,dtype=float).flatten()
55+
X = numpy.asarray(X,dtype=float).flatten()
56+
57+
cost_left = linregress(X, Y_left)
58+
cost_right = linregress(X, Y_right)
59+
60+
print("")
61+
print("\tSlope {:>7.4f} ns {:>7.4f} ns".format(cost_left.slope * 1e6, cost_right.slope* 1e6))
62+
print("\tIntercept {:>7.4f} s {:>7.4f} s".format(cost_left.intercept, cost_right.intercept))
63+
64+
65+

benchmark/compare_commits.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
wd=`pwd`
4+
root_dir=`realpath "$wd/../"`
5+
6+
echo $wd
7+
echo $root_dir
8+
9+
function benchmark_branch {
10+
cd $root_dir
11+
git checkout $1
12+
head=`git rev-parse --short HEAD`
13+
pip install .
14+
cd $wd
15+
taskset -c 0 python benchmark.py -o result-$1-$head.pkl
16+
}
17+
18+
sleep 5
19+
benchmark_branch $1
20+
sleep 5
21+
benchmark_branch $2
22+

0 commit comments

Comments
 (0)