| 1 |
import csv |
| 2 |
|
| 3 |
# makes math far easier |
| 4 |
import numpy as np |
| 5 |
|
| 6 |
|
| 7 |
def filter_results_by_name(results, substr): |
| 8 |
perfs = [] |
| 9 |
for name, perf in results.items(): |
| 10 |
if substr in name: |
| 11 |
perfs.append(perf) |
| 12 |
return np.array(perfs) |
| 13 |
|
| 14 |
|
| 15 |
def main(): |
| 16 |
# using dicts seems easier at first but we'd have to eventually convert |
| 17 |
# to a list for easy elementwise division or use an ugly loop |
| 18 |
funcs = [] |
| 19 |
main = [] |
| 20 |
new = [] |
| 21 |
|
| 22 |
with open("perf.csv", "r") as f: |
| 23 |
csv_reader = csv.reader(f) |
| 24 |
# skip header row |
| 25 |
next(csv_reader) |
| 26 |
|
| 27 |
# csv is sorted by name so we can assume even rows are main and odd are new |
| 28 |
for indx, (func, median) in enumerate(csv_reader): |
| 29 |
func = func.split("::")[-1] |
| 30 |
# indx is even |
| 31 |
if not (indx % 2): |
| 32 |
funcs.append(func) |
| 33 |
main.append(float(median)) |
| 34 |
else: |
| 35 |
new.append(float(median)) |
| 36 |
|
| 37 |
main = np.array(main) |
| 38 |
new = np.array(new) |
| 39 |
|
| 40 |
relative_perfs = new / main |
| 41 |
# more stats will be included when needed |
| 42 |
print( |
| 43 |
f"The new branch is {round(relative_perfs.mean(), 4)}x faster than the main branch aross all tests!" |
| 44 |
) |
| 45 |
|
| 46 |
results = {} |
| 47 |
|
| 48 |
for func_name, relative_perf in zip(funcs, relative_perfs): |
| 49 |
# this allows us to categorize classes of results, such as encode vs decode |
| 50 |
results[func_name] = relative_perf |
| 51 |
|
| 52 |
encode_perfs = filter_results_by_name(results, "encode") |
| 53 |
decode_perfs = filter_results_by_name(results, "decode") |
| 54 |
print( |
| 55 |
f"The new branch is {round(encode_perfs.mean(), 4)}x faster than the main branch aross encode tests!" |
| 56 |
) |
| 57 |
print( |
| 58 |
f"The new branch is {round(decode_perfs.mean(), 4)}x faster than the main branch aross decode tests!" |
| 59 |
) |
| 60 |
|
| 61 |
|
| 62 |
if __name__ == "__main__": |
| 63 |
main() |