forked from commonwarexyz/monorepo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmarks.html
More file actions
433 lines (389 loc) · 20.7 KB
/
benchmarks.html
File metadata and controls
433 lines (389 loc) · 20.7 KB
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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
<!DOCTYPE html>
<html lang="en">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<link rel="icon" href="favicon.ico" type="image/x-icon">
<title>commonware > Benchmarks</title>
<meta name="description" content="Benchmarks for the Commonware Library.">
<meta name="keywords" content="commonware, open source, common goods, software, internet, ownership, trust, blockchain, decentralization, crypto">
<meta property="og:url" content="https://commonware.xyz/benchmarks.html" />
<meta property="og:type" content="website" />
<meta property="og:site_name" content="commonware > Benchmarks" />
<meta property="og:title" content="commonware > Benchmarks" />
<meta property="og:description" content="Benchmarks for the Commonware Library." />
<meta property="og:image" content="https://commonware.xyz/card.png" />
<meta name="twitter:card" content="summary_large_image" />
<meta property="twitter:domain" content="commonware.xyz" />
<meta property="twitter:url" content="https://commonware.xyz/benchmarks.html" />
<meta property="twitter:title" content="commonware > Benchmarks" />
<meta property="twitter:description" content="Benchmarks for the Commonware Library." />
<meta property="twitter:image" content="https://commonware.xyz/card.png" />
<meta property="twitter:site" content="@commonwarexyz" />
<meta property="twitter:creator" content="@commonwarexyz" />
<meta property="twitter:creator:id" content="@commonwarexyz" />
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="logo-placeholder">
<div class="logo-line">
<span class="edge-logo-symbol">+</span>
<span class="horizontal-logo-symbol">~</span>
<span class="horizontal-logo-symbol"> </span>
<span class="horizontal-logo-symbol">-</span>
<span class="horizontal-logo-symbol">+</span>
<span class="horizontal-logo-symbol">-</span>
<span class="horizontal-logo-symbol">+</span>
<span class="horizontal-logo-symbol"> </span>
<span class="horizontal-logo-symbol">-</span>
<span class="horizontal-logo-symbol">+</span>
<span class="horizontal-logo-symbol">-</span>
<span class="horizontal-logo-symbol">~</span>
<span class="horizontal-logo-symbol">~</span>
<span class="edge-logo-symbol">*</span>
</div>
<div class="logo-line">
<span class="vertical-logo-symbol">|</span>
<span class="logo-text"> commonware </span>
<span class="vertical-logo-symbol"> </span>
</div>
<div class="logo-line">
<span class="edge-logo-symbol">*</span>
<span class="horizontal-logo-symbol">~</span>
<span class="horizontal-logo-symbol">+</span>
<span class="horizontal-logo-symbol">+</span>
<span class="horizontal-logo-symbol">-</span>
<span class="horizontal-logo-symbol"> </span>
<span class="horizontal-logo-symbol">~</span>
<span class="horizontal-logo-symbol">-</span>
<span class="horizontal-logo-symbol">+</span>
<span class="horizontal-logo-symbol"> </span>
<span class="horizontal-logo-symbol">-</span>
<span class="horizontal-logo-symbol">*</span>
<span class="horizontal-logo-symbol">-</span>
<span class="edge-logo-symbol">+</span>
</div>
</div>
<div class="content">
<h1>Benchmarks</h1>
<div class="meta">
<div class="date">Last Updated: <span id="last-update"></span></div>
</div>
<div id="main"></div>
<button id="toggle-expand" onclick="toggleExpand()">expand all</button>
</div>
<div id="footer-placeholder"></div>
<script src="https://cdn.jsdelivr.net/npm/moment@2.29.2/moment.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.2/dist/Chart.min.js"></script>
<script>
'use strict';
// Toggle function to switch between expanding/collapsing all <details> elements
function updateExpandButton() {
const expandBtn = document.getElementById('toggle-expand');
const detailsList = document.querySelectorAll('details');
const anyOpen = Array.from(detailsList).some(d => d.open);
const benchmarkCount = document.querySelectorAll('details.benchmark-graph-details').length;
expandBtn.textContent = anyOpen ? `collapse all (${benchmarkCount})` : `expand all (${benchmarkCount})`;
}
// Toggle function to expand all <details> elements
function toggleExpand() {
const detailsList = document.querySelectorAll('details');
const anyOpen = Array.from(detailsList).some(d => d.open);
detailsList.forEach(d => d.open = !anyOpen);
updateExpandButton();
}
// Compute all-time and 7-day performance changes for a single benchmark
function computeSingleBenchSummary(benches) {
if (!benches || benches.length < 1) {
return { pctAllTime: "N/A", pct7Day: "N/A", latest: "N/A" };
}
// Sort by date ascending
const sorted = [...benches].sort((a, b) => a.date - b.date);
const earliestVal = sorted[0].bench.value; // first
const earliestDate = sorted[0].date;
const latestVal = sorted[sorted.length - 1].bench.value; // last
const latestDate = sorted[sorted.length - 1].date;
if (benches.length < 2) {
return { pctAllTime: "N/A", pct7Day: "N/A", latest: latestVal };
}
// All-time ratio
let pctAllTime = "N/A";
if (earliestVal > 0) {
const ratioAll = (latestVal - earliestVal) / earliestVal;
pctAllTime = (ratioAll * 100).toFixed(1) + "%";
}
// 7-day ratio
const sevenDaysInMs = 7 * 24 * 3600 * 1000;
const cutoffDate = latestDate - sevenDaysInMs;
// find the bench value for the point in time just after or near that date
let sevenDayVal = null;
let minDelta = Number.MAX_VALUE;
for (const point of sorted) {
if (point.date >= cutoffDate) {
const delta = point.date - cutoffDate;
if (delta < minDelta) {
minDelta = delta;
sevenDayVal = point.bench.value;
}
}
}
// if we never found anything after the cutoffDate, fallback to earliest
if (!sevenDayVal) {
sevenDayVal = earliestVal;
}
let pct7Day = "N/A";
if (sevenDayVal > 0) {
const ratio7 = (latestVal - sevenDayVal) / sevenDayVal;
pct7Day = (ratio7 * 100).toFixed(1) + "%";
}
return { pctAllTime, pct7Day, latest: latestVal };
}
function setupBenchmark() {
// Set Chart.js default font family
Chart.defaults.global.defaultFontFamily = 'Consolas, monospace';
Chart.defaults.global.defaultFontColor = "#000";
// Build cases
function init() {
function collectBenchesPerTestCase(entries) {
const moduleMap = new Map();
for (const entry of entries) {
const { commit, date, tool, benches } = entry;
for (const bench of benches) {
// Get module name
const parts = bench.name.split("::");
if (parts.length < 2) continue;
const moduleName = parts[0];
// Get function name and params
const functionPart = parts.slice(1).join("::");
let funcName = functionPart;
let params = "";
if (functionPart.includes("/")) {
[funcName, params] = functionPart.split("/", 2);
}
// Populate result
const result = { commit, date, tool, bench, params };
if (!moduleMap.has(moduleName)) {
moduleMap.set(moduleName, new Map());
}
const functionMap = moduleMap.get(moduleName);
if (!functionMap.has(funcName)) {
functionMap.set(funcName, new Map());
}
const paramsMap = functionMap.get(funcName);
if (!paramsMap.has(params)) {
paramsMap.set(params, [result]);
} else {
paramsMap.get(params).push(result);
}
}
}
return moduleMap;
}
const data = window.BENCHMARK_DATA;
// Render header
document.getElementById('last-update').textContent = new Date(data.lastUpdate).toString();
// Prepare data points for charts
return Object.keys(data.entries).sort().map(name => ({
name,
dataSet: collectBenchesPerTestCase(data.entries[name]),
}));
}
function renderAllCharts(dataSets) {
function renderGraph(parent, name, dataset) {
// Create a <details> wrapper for each individual graph.
const graphDetails = document.createElement('details');
graphDetails.className = 'benchmark-graph-details';
parent.appendChild(graphDetails);
// Listen for "toggle" events on each details to update button state
graphDetails.addEventListener('toggle', updateExpandButton);
// <summary> that shows/hides the graph
const summary = document.createElement('summary');
summary.textContent = name;
const { pctAllTime, pct7Day, latest } = computeSingleBenchSummary(dataset);
const value = latest / 1e6;
const units = "ms";
summary.innerHTML = `
<span class="benchmark-graph-title">${name}</span>
<br>
<span class="benchmark-performance">${value} ${units} | All-Time: ${pctAllTime} (Last 7 Days: ${pct7Day})</span>
`;
graphDetails.appendChild(summary);
// Create the <canvas> inside the <details>
const canvas = document.createElement('canvas');
canvas.className = 'benchmark-chart';
graphDetails.appendChild(canvas);
// Create chart
const data = {
datasets: [{
label: name,
data: dataset.map(d => {
return { x: new Date(d.commit.timestamp), y: d.bench.value };
}),
borderColor: '#000000',
backgroundColor: '#000000' + '60'
}]
};
const options = {
scales: {
xAxes: [{
type: 'time',
time: {
unit: 'day',
displayFormats: {
day: 'M/D'
},
},
ticks: {
autoSkip: true,
maxTicksLimit: 5,
},
scaleLabel: {
display: false,
},
gridLines: {
display: true,
}
}],
yAxes: [{
scaleLabel: {
display: true,
labelString: 'ms/iter',
},
ticks: {
beginAtZero: true,
autoSkip: true,
maxTicksLimit: 7,
callback: function (value) {
return (value / 1e6);
}
},
gridLines: {
display: true,
}
}]
},
legend: { display: false },
tooltips: {
callbacks: {
afterTitle: items => {
const { index } = items[0];
const data = dataset[index];
return '\n' + data.commit.message
+ '\n\nCommitted by ' + data.commit.author.name + ' (@' + data.commit.author.username + ') at ' + data.commit.timestamp + '\n';
},
label: function (item) {
let rawVal = Number(item.value);
// Convert from ns -> ms (divide by 1e6)
let val = rawVal / 1e6;
// Format numeric output
let label = val.toLocaleString(undefined, {
minimumFractionDigits: 3,
maximumFractionDigits: 3
});
const { range, unit } = dataset[item.index].bench;
label += ' ms/iter';
if (range) {
// parse numeric range if it exists, also convert to ms if needed
let rangeVal = range.replace(/[^\d.]/g, '');
let rangeNum = Number(rangeVal);
if (!isNaN(rangeNum)) {
rangeNum = rangeNum / 1e6;
}
label += ' (' + rangeNum.toLocaleString(undefined, {
minimumFractionDigits: 3,
maximumFractionDigits: 3
}) + ' ms)';
}
return label;
},
afterLabel: item => {
const { extra } = dataset[item.index].bench;
return extra ? '\n' + extra : '';
}
}
},
onClick: (_mouseEvent, activeElems) => {
if (activeElems.length === 0) return;
const index = activeElems[0]._index;
const url = dataset[index].commit.url;
window.open(url, '_blank');
},
title: {
display: false,
},
};
new Chart(canvas, {
type: 'line',
data,
options,
});
}
function renderBenchSet(testName, benchSet, main) {
// Setup the <details> element for the benchmark set
const detailsElem = document.createElement('details');
detailsElem.className = 'benchmark-set';
main.appendChild(detailsElem);
// Listen to "toggle" so button updates if a single set is opened/closed
detailsElem.addEventListener('toggle', updateExpandButton);
// Create the <summary> element for the benchmark set
const summaryElem = document.createElement('summary');
summaryElem.className = 'benchmark-title';
summaryElem.textContent = testName;
detailsElem.appendChild(summaryElem);
// Create the container for the modules
const moduleContainer = document.createElement('div');
moduleContainer.className = 'benchmark-modules';
detailsElem.appendChild(moduleContainer);
// Iterate over modules, sorted alphabetically
Array.from(benchSet.keys()).sort().forEach(moduleName => {
const functionMap = benchSet.get(moduleName);
const moduleDetails = document.createElement('details');
moduleDetails.className = 'benchmark-module';
moduleContainer.appendChild(moduleDetails);
moduleDetails.addEventListener('toggle', updateExpandButton);
const moduleSummary = document.createElement('summary');
moduleSummary.className = 'module-title';
moduleSummary.textContent = moduleName;
moduleDetails.appendChild(moduleSummary);
const functionContainer = document.createElement('div');
functionContainer.className = 'module-functions';
moduleDetails.appendChild(functionContainer);
// Iterate over functions within the module, sorted alphabetically
Array.from(functionMap.keys()).sort().forEach(funcName => {
const paramsMap = functionMap.get(funcName);
const functionDetails = document.createElement('details');
functionDetails.className = 'benchmark-function';
functionContainer.appendChild(functionDetails);
functionDetails.addEventListener('toggle', updateExpandButton);
const functionSummary = document.createElement('summary');
functionSummary.className = 'function-title';
functionSummary.textContent = funcName;
functionDetails.appendChild(functionSummary);
const paramsContainer = document.createElement('div');
paramsContainer.className = 'function-params';
functionDetails.appendChild(paramsContainer);
// Iterate over parameter sets within the function
paramsMap.forEach((results, params) => {
const chartTitle = params ? params : "default";
renderGraph(paramsContainer, chartTitle, results);
});
});
});
}
// Render all benchmarks
const main = document.getElementById('main');
for (const { name, dataSet } of dataSets) {
renderBenchSet(name, dataSet, main);
}
}
// Render all charts
renderAllCharts(init());
// Update buttons
updateExpandButton();
};
</script>
<script src="https://commonwarexyz.github.io/benchmarks/data.js" onload="setupBenchmark()"></script>
<script src="shared.js"></script>
<script defer src='https://static.cloudflareinsights.com/beacon.min.js' data-cf-beacon='{"token": "07159b86f75b4af18e54dd0cda2fb4a7"}'></script>
</body>
</html>