-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
324 lines (281 loc) · 12.3 KB
/
index.html
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
<!doctype html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body>
<div class="container-fluid" style="padding: 20px;">
<div class="row">
<div class="col-xl card" style="margin: 5px">
<div class="card-body">
<div id="version-select" class="btn-group-lg btn-group-toggle" data-toggle="buttons"></div>
<small class="form-text text-muted">scala-uri version</small>
</div>
</div>
<div class="col-xl card" style="margin: 5px">
<div class="card-body">
<select id="benchmarks-select" class="custom-select custom-select-lg" onchange="redrawChart()">
</select>
<small class="form-text text-muted">benchmark</small>
</div>
</div>
<div class="col-xl-2 card" style="margin: 5px">
<div class="card-body">
<select id="unit-select" class="custom-select custom-select-lg" onchange="redrawChart()">
<option value="score">score</option>
<option value="0.0">0.0</option>
<option value="50.0">50.0</option>
<option value="90.0">90.0</option>
<option value="95.0">95.0</option>
<option value="99.0">99.0</option>
<option value="99.9">99.9</option>
<option value="99.99">99.99</option>
<option value="99.999">99.999</option>
<option value="99.9999">99.9999</option>
<option value="100.0">100.0</option>
</select>
<small class="form-text text-muted">metric</small>
</div>
</div>
</div>
<div class="row">
<div class="col card" style="min-width: 800px; margin: 5px">
<div class="card-body">
<canvas id="chart"></canvas>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script>
<script type="text/javascript">
var datasets = [];
var versionSeries = {}
var versionJmhJsons = {}
var benchmarksSelect = document.getElementById('benchmarks-select');
var unitSelect = document.getElementById('unit-select');
const possibleXAxes = [
'publicSuffixLength',
'uriPartLength',
'uriParts',
'pieceLength',
'amount'
];
const checkedByDefault = [
'1.5.1',
'2.0.0',
'3.6.0',
'4.0.0'
];
const chartColors = {
red: 'rgb(255, 99, 132)',
orange: 'rgb(255, 159, 64)',
yellow: 'rgb(255, 205, 86)',
green: 'rgb(75, 192, 192)',
blue: 'rgb(54, 162, 235)',
purple: 'rgb(153, 102, 255)',
grey: 'rgb(201, 203, 207)'
};
function get(url, f) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.onload = function() {
if (xhr.status === 200) {
f(JSON.parse(xhr.responseText));
}
else {
console.log('Request failed. Returned status of ' + xhr.status);
}
};
xhr.send();
}
function findXAxis(jmhJson, selectedBenchmark) {
for(var i = 0; i < jmhJson.length; i++) {
var jmhResult = jmhJson[i];
if(jmhResult.benchmark == selectedBenchmark) {
for(var j = 0; j < possibleXAxes.length; j++) {
var possibleXAxis = possibleXAxes[j];
if(jmhResult.params[possibleXAxis] != null) {
return possibleXAxis;
}
}
}
}
return null;
}
function findSeries(jmhJson, version) {
var series = {};
for(var i = 0; i < jmhJson.length; i++) {
var jmhResult = jmhJson[i];
var benchmark = jmhResult.benchmark;
var params = [];
var paramNames = Object.keys(jmhResult.params);
var paramsKey = '';
for(var j = 0; j < paramNames.length; j++) {
var paramName = paramNames[j];
if(!possibleXAxes.includes(paramName)) {
var paramValue = jmhResult.params[paramName];
paramsKey += '(' + paramName + '=' + paramValue + ')';
params.push({
key: paramName,
value: paramValue
});
}
}
series[benchmark + paramsKey] = {
name: version + paramsKey,
benchmark: benchmark,
params: params
};
}
return Object.values(series);
}
function paramsMatch(jmhResult, thisSeries) {
for(var i = 0; i < thisSeries.params.length; i++) {
var param = thisSeries.params[i];
if(jmhResult.params[param.key] != param.value) {
return false;
}
}
return true;
}
function addToChart(jmhJson, version) {
console.log(jmhJson);
var series = findSeries(jmhJson, version);
versionSeries[version] = series;
versionJmhJsons[version] = jmhJson;
console.log(versionSeries);
// Prevents race-conditions when this function is called several times on first page load
var versionsSelected = $('#version-select .active').length;
var versionsGenerated = Object.keys(versionSeries).length;
if(versionsGenerated == versionsSelected) {
redrawBenchmarksSelect();
redrawChart();
}
}
function redrawBenchmarksSelect() {
var benchmarks = new Set();
Object.values(versionSeries).forEach(function(series) {
series.forEach(function(aSeries) {
benchmarks.add(aSeries.benchmark.replace('io.lemonlabs.uri.', ''));
});
});
benchmarksSelect.innerHTML = '';
benchmarks.forEach(function(benchmark) {
benchmarksSelect.innerHTML += '<option value="' + benchmark + '">' + benchmark + '</option>';
});
}
function redrawChart() {
datasets = [];
var selectedBenchmark = 'io.lemonlabs.uri.' + benchmarksSelect.value;
var colorNames = Object.keys(chartColors);
var xAxis;
var yAxis;
Object.keys(versionSeries).forEach(function(version) {
var selectedUnit = unitSelect.value;
var series = versionSeries[version];
var jmhJson = versionJmhJsons[version];
xAxis = findXAxis(jmhJson, selectedBenchmark);
for(var i = 0; i < series.length; i++) {
var thisSeries = series[i];
if(thisSeries.benchmark != selectedBenchmark) {
continue;
}
var data = [];
for(var j = 0; j < jmhJson.length; j++) {
var jmhResult = jmhJson[j];
yAxis = jmhResult.primaryMetric.scoreUnit
var theseParamsMatch = paramsMatch(jmhResult, thisSeries);
if(jmhResult.benchmark == selectedBenchmark && theseParamsMatch) {
console.log(jmhResult.benchmark + ' matches!');
var metric = jmhJson[j].primaryMetric;
var yVal = selectedUnit == 'score' ? metric.score: metric.scorePercentiles[selectedUnit];
data.push({
x: jmhJson[j].params[xAxis],
y: yVal
});
}
}
if(data.length > 0) {
var colorName = colorNames[datasets.length % colorNames.length];
var newColor = chartColors[colorName];
datasets.push({
label: thisSeries.name,
data: data,
backgroundColor: newColor,
borderColor: newColor,
showLine: true,
fill: false
});
}
}
});
console.log(datasets);
var ctx = document.getElementById('chart').getContext('2d');
var scatterChart = new Chart(ctx, {
type: 'scatter',
data: {
datasets: datasets
},
options: {
scales: {
xAxes: [{
type: 'linear',
position: 'bottom',
scaleLabel: {
display: true,
labelString: xAxis
}
}],
yAxes: [{
scaleLabel: {
display: true,
labelString: yAxis
}
}]
},
animation: {
duration: 0
},
legend: {
position: 'bottom',
fullWidth: false,
labels: {
fontSize: 10
}
}
}
});
}
function populateVersionSelect(versions) {
var versionSelect = document.getElementById('version-select');
for (var version of versions) {
var check = checkedByDefault.includes(version);
var checkedAttr = check ? 'checked': '';
var activeAttr = check ? 'active': '';
versionSelect.innerHTML += '<label style="margin: 2px;" class="btn btn-secondary ' + activeAttr + '">' +
'<input id="' + version + '-checkbox" ' + checkedAttr + ' onchange="versionClicked(\'' + version + '\');" type="checkbox" checked autocomplete="off">' + version + '</label>';
if(check) {
addVersion(version);
}
}
}
function addVersion(ver) {
get('jmh-' + ver + '.json', function(r) { addToChart(r, ver) });
}
function versionClicked(ver) {
if(document.getElementById(ver + '-checkbox').checked) {
addVersion(ver)
} else {
delete versionSeries[ver];
redrawBenchmarksSelect();
redrawChart();
}
}
get('jmh-scala-uri-versions.json', populateVersionSelect)
</script>
</body>
</html>