|
| 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 | + |
0 commit comments