|
6 | 6 |
|
7 | 7 | import sys
|
8 | 8 |
|
9 |
| -''' |
| 9 | +""" |
| 10 | +
|
10 | 11 | Example of parsed format:
|
11 | 12 |
|
12 | 13 | test_base64 (test_benchmark.benchmark) ...
|
13 | 14 | Running benchmarker: NativeBenchmarker: clang
|
14 | 15 | clang: mean: 0.731 (+-0.012) secs median: 0.727 range: 0.715-0.746 (noise: 1.589%) (5 runs)
|
15 | 16 | Running benchmarker: NativeBenchmarker: gcc
|
16 | 17 | [..]
|
17 |
| -''' |
| 18 | +""" |
| 19 | + |
18 | 20 |
|
19 |
| -benchmark = '' |
20 |
| -benchmarker = '' |
21 |
| -matrix = [] |
| 21 | +def main(args): |
| 22 | + benchmark = '' |
| 23 | + benchmarker = '' |
| 24 | + # the first line has: [<empty string>, benchmarker name 1, ..] |
| 25 | + # other lines have: [benchmark name, result 1 , ..] |
| 26 | + matrix = [] |
22 | 27 |
|
23 |
| -for line in open(sys.argv[1]).readlines(): |
24 |
| - line = line.strip() |
25 |
| - if line.startswith('test_'): |
26 |
| - benchmark = line.split(' ')[0][5:] |
27 |
| - # print('benchmark:', benchmark) |
28 |
| - if len(matrix) == 0: |
29 |
| - # the first line has [(free space), benchmarker name 1, ..] |
30 |
| - matrix += [[' ']] |
31 |
| - # other lines have [benchmark name, result 1, ..] |
32 |
| - matrix += [[benchmark]] |
33 |
| - if line.startswith('Running benchmarker'): |
34 |
| - benchmarker = line.split(':')[-1].strip() |
35 |
| - if benchmarker not in matrix[0]: |
36 |
| - matrix[0] += [benchmarker] |
37 |
| - # print('benchmarker:', benchmarker) |
38 |
| - elif line.startswith(benchmarker + ':'): |
39 |
| - parts = line.strip().split(' ') |
40 |
| - mean = float(parts[2]) |
41 |
| - median = float(parts[7]) |
42 |
| - noise = float(parts[13][:-2]) |
43 |
| - if noise > 5: |
44 |
| - print('warning: noisy! (%s: %f%%)' % (benchmark + '.' + benchmarker, noise)) |
45 |
| - if abs(mean - median) / mean > 0.05: |
46 |
| - print('warning: mean and median diverge! (%s: %f vs %f)' % (benchmark + '.' + benchmarker, mean, median)) |
47 |
| - # print(benchmark, benchmarker, mean, median, noise) |
48 |
| - matrix[-1] += [median] |
| 28 | + for line in open(args[0]).readlines(): |
| 29 | + line = line.strip() |
| 30 | + if line.startswith('test_'): |
| 31 | + benchmark = line.split(' ')[0][5:] |
| 32 | + # print('benchmark:', benchmark) |
| 33 | + if len(matrix) == 0: |
| 34 | + # the first line has [(free space), benchmarker name 1, ..] |
| 35 | + matrix += [[' ']] |
| 36 | + # other lines have [benchmark name, result 1, ..] |
| 37 | + matrix += [[benchmark]] |
| 38 | + elif line.startswith('Running benchmarker'): |
| 39 | + benchmarker = line.split(':')[-1].strip() |
| 40 | + if benchmarker not in matrix[0]: |
| 41 | + matrix[0] += [benchmarker] |
| 42 | + # print('benchmarker:', benchmarker) |
| 43 | + elif line.startswith(benchmarker + ':'): |
| 44 | + parts = line.split(' ') |
| 45 | + mean = float(parts[2]) |
| 46 | + median = float(parts[7]) |
| 47 | + noise = float(parts[13][:-2]) |
| 48 | + if noise > 5: |
| 49 | + print('warning: noisy! (%s: %f%%)' % (benchmark + '.' + benchmarker, noise)) |
| 50 | + if abs(mean - median) / mean > 0.05: |
| 51 | + print('warning: mean and median diverge! (%s: %f vs %f)' % (benchmark + '.' + benchmarker, mean, median)) |
| 52 | + # print(benchmark, benchmarker, mean, median, noise) |
| 53 | + matrix[-1] += [median] |
49 | 54 |
|
50 |
| -# normalize results |
51 |
| -for line in matrix[1:]: |
52 |
| - if len(line) >= 2: |
53 |
| - base = line[1] |
54 |
| - for i in range(1, len(line)): |
55 |
| - line[i] = line[i] / base |
| 55 | + # normalize results |
| 56 | + for line in matrix[1:]: |
| 57 | + if len(line) >= 2: |
| 58 | + base = line[1] |
| 59 | + for i in range(1, len(line)): |
| 60 | + line[i] = line[i] / base |
56 | 61 |
|
57 |
| -col0_width = max(len(r[0]) for r in matrix) |
| 62 | + col0_width = max(len(r[0]) for r in matrix) |
58 | 63 |
|
59 |
| -# filter results |
60 |
| -result = [] |
61 |
| -for i, row in enumerate(matrix): |
62 |
| - if len(row) != len(matrix[0]): |
63 |
| - print('warning: not enough results, skipping row:', row[0]) |
64 |
| - else: |
65 |
| - line = '%*s ' % (col0_width, row[0]) |
66 |
| - if i == 0: |
67 |
| - line += '\t'.join([str(x) for x in row[1:]]) |
| 64 | + # filter results |
| 65 | + result = [] |
| 66 | + for i, row in enumerate(matrix): |
| 67 | + if len(row) != len(matrix[0]): |
| 68 | + print('warning: not enough results, skipping row:', row[0]) |
68 | 69 | else:
|
69 |
| - line += '\t'.join(['%.3f' % x for x in row[1:]]) |
70 |
| - result.append(line) |
| 70 | + line = '%*s ' % (col0_width, row[0]) |
| 71 | + if i == 0: |
| 72 | + line += '\t'.join([str(x) for x in row[1:]]) |
| 73 | + else: |
| 74 | + line += '\t'.join(['%.3f' % x for x in row[1:]]) |
| 75 | + result.append(line) |
| 76 | + |
| 77 | + # print results |
| 78 | + print() |
| 79 | + print('\n'.join(result)) |
| 80 | + print() |
| 81 | + |
71 | 82 |
|
72 |
| -# print results |
73 |
| -print() |
74 |
| -print('\n'.join(result)) |
75 |
| -print() |
| 83 | +if __name__ == '__main__': |
| 84 | + sys.exit(main(sys.argv[1:])) |
0 commit comments