-
Notifications
You must be signed in to change notification settings - Fork 3
/
make_perf_charts.py
executable file
·144 lines (124 loc) · 4.33 KB
/
make_perf_charts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env python3
import itertools
import json
import math
import pygal
import argparse
parser = argparse.ArgumentParser(description='Takes data from a Google Benchmark JSON file, and makes a bunch of pretty pictires.')
parser.add_argument('json_file', type=str, help='Google Benchmark JSON file to proccess.')
args = parser.parse_args()
f = open(args.json_file, 'r')
samples = json.load(f)
samples = samples['benchmarks']
styles = {}
def get_style(run_names):
key = ''.join(run_names)
return styles[key]
styles[''.join(['Old', 'New'])] = \
pygal.style.Style(
background='transparent',
plot_background='transparent',
colors=('#FF0000', '#0000FF'))
styles[''.join(['Old', 'New', 'Fat New'])] = \
pygal.style.Style(
background='transparent',
plot_background='transparent',
colors=('#FF0000', '#00FF00', '#007F7F'))
styles[''.join(['Old Owned Pattern', 'Old Subrange Pattern', 'Old Single',
'New Owned Pattern', 'New Subrange Pattern', 'New Single'])] = \
pygal.style.Style(
background='transparent',
plot_background='transparent',
colors=('#FF0000', '#FF3F00', '#FF7F00', '#00FF00', '#007F7F', '#0000FF'))
def next_largest_power_10(x):
return 10 ** math.ceil(math.log10(x))
def chunk(r, n = 1):
l = len(r)
for i in range(0, l, n):
yield r[i:min(i + n, l)]
def common_prefix(names):
zipped = zip(*curr_run_names)
prefixes = itertools.takewhile(lambda x: all(x[0] == y for y in x), zipped)
return ''.join(x[0] for x in prefixes)
def names_and_runs(run, run_names):
prefix = common_prefix(run_names)
name = prefix[:-1] if prefix.endswith('_') else prefix
run_names = map(lambda x: x[len(prefix):], run_names)
run_names = list(map(lambda x: ' '.join(map(lambda y: y.title(), x.split('_'))), run_names))
runs = list(chunk(run, len(all_iterations)))
return (name, run_names, runs)
def print_chart(run, run_names):
name, run_names, runs = names_and_runs(run, run_names)
style = get_style(run_names)
chart = pygal.Line(
style=style,
logarithmic=True,
y_title='Nanoseconds',
x_title='Number of Elements',
tooltip_border_radius=10,
legend_at_bottom=True)
title = name
if title.startswith('ptr_'):
title = title[len('ptr_'):] + '_view (Function Pointer)'
else:
title += '_view'
chart.title = title
chart.x_labels = list(map(lambda x: str(x), all_iterations))
for name_,run_ in zip(run_names, runs):
# print(name, name_, run_)
chart.add(name_, run_, show_dots=False)
with open(f'{name}.svg', 'w') as out_f:
out_f.write(str(chart.render(2)))
def print_table(run, run_names):
name, run_names, runs = names_and_runs(run, run_names)
label = 'Run \\ `N`'
longest = max(map(lambda x: len(x), run_names + [label]))
sep = '+-' + '-' * longest + '-+'
hdr = f'| {label:<{longest}} |'
hdr_sep = '+=' + '=' * longest + '=+'
for x in all_iterations:
sep += '-' * 9 + '+'
hdr += f'{x:<8} |'
hdr_sep += ':' + '=' * 7 + ':+'
print(f'=== {name} ===')
print(sep)
print(hdr)
print(hdr_sep)
for name_,run_ in zip(run_names, runs):
row = f'| {name_:{longest}} |'
for x in run_:
row += f'{x:<8} |'
print(row)
print(sep)
print('\n')
all_iterations = []
runs = {}
prev_name = ''
prev_prefix = ''
prev_iterations = 10 ** 10
curr_run = []
curr_run_names = []
for sample in samples:
name = sample['name'][3:] # Carve off 'BM_' prefix.
name,iterations = name.split('/')
if iterations.endswith('k'):
iterations = next_largest_power_10(float(iterations[:-1]) * 1024)
else:
iterations = int(iterations)
if iterations not in all_iterations:
all_iterations.append(iterations)
cpu_time = int(sample['cpu_time'])
prefix = name.split('_')[0]
if prefix != prev_prefix and len(curr_run):
print_chart(curr_run, curr_run_names)
print_table(curr_run, curr_run_names)
curr_run = []
curr_run_names = []
curr_run.append(cpu_time)
if iterations < prev_iterations:
curr_run_names.append(name)
prev_name = name
prev_prefix = prefix
prev_iterations = iterations
print_chart(curr_run, curr_run_names)
print_table(curr_run, curr_run_names)