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