|
| 1 | +import argparse |
| 2 | +import pickle |
| 3 | +import numpy |
| 4 | + |
| 5 | +parser = argparse.ArgumentParser(description='Compare two benchmarks.', |
| 6 | + formatter_class=argparse.ArgumentDefaultsHelpFormatter) |
| 7 | +parser.add_argument('left', help='First input for comparison') |
| 8 | +parser.add_argument('right', help='Second input for comparison') |
| 9 | +parser.add_argument('-s', help='short output', action='store_false') |
| 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(numpy.mean(left_val)) |
| 45 | + Y_right.append(numpy.mean(right_val)) |
| 46 | + X.append(numpy.full([1], it)) |
| 47 | + |
| 48 | + if args.s: |
| 49 | + print("\t\tInterations {}".format(it)) |
| 50 | + print("\t\tMean: {:>7.4f} s {:>7.4f} s".format(numpy.mean(left_val), numpy.mean(right_val))) |
| 51 | + print("\t\tMedian: {:>7.4f} s {:>7.4f} s".format( |
| 52 | + numpy.quantile(left_val, 0.50), numpy.quantile(right_val, 0.50))) |
| 53 | + print("\t\t5%: {:>7.4f} s {:>7.4f} s".format( |
| 54 | + numpy.quantile(left_val, 0.05), numpy.quantile(right_val, 0.05))) |
| 55 | + print("\t\t95%: {:>7.4f} s {:>7.4f} s".format( |
| 56 | + numpy.quantile(left_val, 0.95), numpy.quantile(right_val, 0.95))) |
| 57 | + Y_left = numpy.asarray(Y_left, dtype=float).flatten() |
| 58 | + Y_right = numpy.asarray(Y_right, dtype=float).flatten() |
| 59 | + X = numpy.asarray(X, dtype=float).flatten() |
| 60 | + |
| 61 | + cost_left = numpy.polyfit(X, Y_left, 1) |
| 62 | + cost_right = numpy.polyfit(X, Y_right, 1) |
| 63 | + |
| 64 | + if args.s: |
| 65 | + print("") |
| 66 | + print("\tSlope {:>7.4f} us {:>7.4f} us".format(cost_left[0] * 1e6, cost_right[0] * 1e6)) |
| 67 | + print("\tIntercept {:>7.4f} s {:>7.4f} s".format(cost_left[1], cost_right[1])) |
0 commit comments