|
2 | 2 | import csv |
3 | 3 | import tabulate as tab |
4 | 4 |
|
5 | | -csv_filename = sys.argv[1] |
| 5 | +csv_benchmark = sys.argv[1] |
| 6 | +csv_baseline = sys.argv[2] |
6 | 7 |
|
7 | | -with open(csv_filename) as csv_file: |
| 8 | +def html_inline(x): |
| 9 | + if x == 0: |
| 10 | + color = "black" |
| 11 | + x = "{:.1f}".format(x) |
| 12 | + elif x < 0: |
| 13 | + color = "green" |
| 14 | + x = "{:.1f}".format(x) |
| 15 | + elif x > 0: |
| 16 | + color = "red" |
| 17 | + x = "+{:.1f}".format(x) |
| 18 | + return f"<span style=\"color:{color}\">{x}</span>" |
| 19 | + |
| 20 | +with open(csv_benchmark) as csv_file: |
| 21 | + csv_reader = csv.reader(csv_file) |
| 22 | + next(csv_reader) |
| 23 | + table_benchmark = [row for row in csv_reader] |
| 24 | + |
| 25 | +with open(csv_baseline) as csv_file: |
8 | 26 | csv_reader = csv.reader(csv_file) |
9 | | - header = next(csv_reader) |
10 | | - table = [row for row in csv_reader] |
| 27 | + next(csv_reader) |
| 28 | + table_baseline = [row for row in csv_reader] |
| 29 | + |
| 30 | +table = [] |
| 31 | +for benchmark, baseline in zip(table_benchmark, table_baseline): |
| 32 | + assert(benchmark[0] == baseline[0] and benchmark[2:4] == baseline[2:4]) |
| 33 | + name = benchmark[0] |
| 34 | + time = benchmark[1] |
| 35 | + d = float(baseline[1]) - float(benchmark[1]) |
| 36 | + difference = html_inline(d) |
| 37 | + percent = html_inline(100 * d / float(baseline[1])) |
| 38 | + count = benchmark[2] |
| 39 | + events = benchmark[3] |
| 40 | + table.append([name, time, difference, percent, count, events]) |
11 | 41 |
|
| 42 | +header = ["name", "time", "difference", "percent", "count", "events"] |
12 | 43 | print(tab.tabulate(table, header, tablefmt="github")) |
0 commit comments