-
Notifications
You must be signed in to change notification settings - Fork 9
/
plot.py
executable file
·234 lines (203 loc) · 6.6 KB
/
plot.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#!/usr/bin/env python3
import sys
from turtle import width
from unittest import TestCase
import pygal
from PIL import Image
def read_data(files):
benchs = {}
# only to keep list shorted
names = ["kanal", "kanal-async", "kanal-std-mutex", "kanal-std-mutex-async",
"crossbeam-channel", "flume", "flume-async", "async-channel", "std::mpsc", "futures-channel"]
for f in files:
with open(f) as f:
lines = f.readlines()
if len(lines) < 2:
continue
name = lines[0].strip("\n ")
if name not in names:
names.append(name)
for line in lines[1:]:
test, nsecs, ops = line.strip("\n ").split(",")
splt = test.split('_')
test_cat = splt[0]
test_name = '_'.join(splt[1:])
if test_cat not in benchs:
benchs[test_cat] = {}
if test_name not in benchs[test_cat]:
benchs[test_cat][test_name] = {}
#benchs[test_cat][test_name][name] = float(nsecs)
benchs[test_cat][test_name][name] = float(ops)
return benchs, names
labels = ["seq", "spsc", "mpsc", "mpmc"] # "select_rx", "select_both"
variants = ["empty", "usize", "big"]
def sortFn(key):
label, variant = key.split("(")
variant = variant[:-1]
v = labels.index(label)*10+variants.index(variant)*1
return v
titles = {
"bounded0": "Bounded Channel With Size 0 Benchmark\n(Operations per second, Higher is better)",
"bounded1": "Bounded Channel With Size 1 Benchmark\n(Operations per second, Higher is better)",
"bounded": "Bounded Channel With Size N Benchmark\n(Operations per second, Higher is better)",
"unbounded": "Unbounded Channel Benchmark\n(Operations per second, Higher is better)",
}
def is_all_none(arr):
for v in arr:
if v is not None:
return False
return True
color_set = {
'magenta': '#ff00ff',
'maroon': '#800000',
'navy': '#000080',
'olive': '#808000',
'orange': '#ffa500',
'purple': '#800080',
'lightpurple': '#eb50eb',
'red': '#ff0000',
'aqua': '#00ffff',
'black': '#000000',
'blue': '#0000ff',
'brown': '#301607',
'cyan': '#00ffff',
'darkblue': '#00008b',
'darkcyan': '#008b8b',
'darkgrey': '#a9a9a9',
'darkgreen': '#006400',
'darkkhaki': '#bdb76b',
'darkmagenta': '#8b008b',
'darkolivegreen': '#556b2f',
'darkorange': '#ff8c00',
'darkorchid': '#9932cc',
'darkred': '#8b0000',
'darksalmon': '#e9967a',
'darkviolet': '#9400d3',
'fuchsia': '#ff00ff',
'gold': '#dbb900',
'lightgold': '#fad302',
'azure': '#19ffae',
'indigo': '#4b0082',
'khaki': '#f0e68c',
'lime': '#00ff00',
'lightblue': "#3dc2ff",
'lightbrown': "#7a4d32",
'green': "#0aa16b"
}
colors = {
"kanal": "green",
"kanal-async": "azure",
"kanal-std-mutex": "gold",
"kanal-std-mutex-async": "lightgold",
"go": "blue",
"flume": "purple",
"flume-async": "lightpurple",
"async-channel": "lightblue",
"crossbeam-channel": "red",
"std::mpsc": "brown",
"futures-channel": "lightbrown",
}
def get_color(name):
if name.find("go") == 0:
name = "go"
if name in colors:
return color_set[colors[name]]
reserved = sorted(colors.values())
for k in color_set:
if k not in reserved:
colors[name] = k
return color_set[k]
def make_rows(bench_name, bench, names):
# bench_keys = sorted(bench.keys())
bench_keys = list(bench.keys())
bench_keys.sort(key=sortFn)
x_labels = bench_keys
for label in labels:
if label in bench_keys:
x_labels.append(label)
rows = []
for name in names:
row = []
for label in x_labels:
if name in bench[label]:
# row.append(round(bench[label][name]/1e9, 2)) # convert to seconds
row.append(bench[label][name])
else:
row.append(None)
rows.append((name, row))
return rows, x_labels
def normalize_rows(rows):
norm = []
for (name, row) in rows:
if name == "kanal":
norm = row
for idx, (name, row) in enumerate(rows):
rows[idx] = (
name, [round(i / j, 2) if i is not None else 0 for i, j in zip(row, norm)])
def set_zero_none_fields(rows):
norm = []
for (name, row) in rows:
if name == "kanal":
norm = row
for idx, (name, row) in enumerate(rows):
rows[idx] = (
name, [i if i is not None else 0 for i, j in zip(row, norm)])
def concat_vertical(imgs, to):
height_sum = 0
for img in imgs:
height_sum += img.height+5
output = Image.new('RGB', (imgs[0].width, height_sum))
last_height = 0
for img in imgs:
output.paste(img, (0, last_height))
last_height += img.height+5
output.save(to)
def chart(benchs, names):
for bench_name in benchs:
bench = benchs[bench_name]
rows, label_list = make_rows(bench_name, bench, names)
x_labels = label_list # []
for label in labels:
if label in label_list:
x_labels.append(label)
bar_colors = []
for (name, _) in rows:
bar_colors.append(get_color(name))
custom_style = pygal.style.Style(
colors=bar_colors, value_font_size=9,
value_colors=bar_colors,
legend_font_size=10,
title_font_size=12,
)
chart = pygal.Bar(
margin=5,
width=1200,
height=350,
legend_at_bottom=True,
print_values=True,
print_values_position='top',
value_formatter=lambda x: '{}M'.format(
round(x/1e6, 1) if x > 1e5 else round(x/1e6, 2)
) if x > 0 else "N/A",
style=custom_style
)
chart.title = titles[bench_name]
chart.x_labels = x_labels
# normalize_rows(rows)
set_zero_none_fields(rows)
for (name, row) in rows:
chart.add(name, row)
chart.render_to_png("target/plot_{}.png".format(bench_name))
chart.render_to_file("target/plot_{}.svg".format(bench_name))
imgs = []
for bench_name in ["bounded0",
"bounded1",
"bounded",
"unbounded"]:
imgs.append(Image.open("target/plot_{}.png".format(bench_name)))
concat_vertical(imgs, "target/results.png")
def main():
benchs, names = read_data(sys.argv[1:])
chart(benchs, names)
if __name__ == '__main__':
main()