Repository navigation
Expand file tree
/
Copy pathbench-dom-bindings.js
More file actions
130 lines (105 loc) · 3.55 KB
/
Copy pathbench-dom-bindings.js
File metadata and controls
130 lines (105 loc) · 3.55 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
sourceMap.SourceMapConsumer.initialize({
"lib/mappings.wasm": "../lib/mappings.wasm?bust_cache=" + String(Math.random()).replace(/0\./, "")
});
function bindRange(labelId, updater) {
const label = document.getElementById(labelId);
const input = label.querySelector("input");
input.addEventListener("input", e => {
e.preventDefault();
updater(input.value);
});
updater(input.value);
}
bindRange("warm-up-iters", input => {
const value = parseInt(input, 10);
WARM_UP_ITERATIONS = value;
});
bindRange("bench-iters", input => {
const value = parseInt(input, 10);
BENCH_ITERATIONS = value;
});
const whichMap = document.getElementById("input-map");
const multiplyBy = document.getElementById("multiply-size-by");
var testSourceMap = SCALA_JS_RUNTIME_SOURCE_MAP;
const updateTestSourceMap = () => {
const origMap = window[whichMap.value];
testSourceMap = JSON.parse(JSON.stringify(origMap));
const factor = parseInt(multiplyBy.value, 10);
if (factor === 1) {
return;
}
const mappings = new Array(factor);
mappings.fill(origMap.mappings);
testSourceMap.mappings = mappings.join(";");
for (let i = 0; i < factor; i++) {
testSourceMap.sources.splice(testSourceMap.sources.length, 0, ...origMap.sources);
testSourceMap.names.splice(testSourceMap.names.length, 0, ...origMap.names);
}
};
updateTestSourceMap();
whichMap.addEventListener("input", e => {
e.preventDefault();
updateTestSourceMap();
});
multiplyBy.addEventListener("input", e => {
e.preventDefault();
updateTestSourceMap();
});
var implAndBrowser = "<unknown>";
const implAndBrowserInput = document.getElementById("impl-and-browser");
const updateImplAndBrowser = () => {
implAndBrowser = implAndBrowserInput.value;
};
implAndBrowserInput.addEventListener("input", updateImplAndBrowser);
updateImplAndBrowser();
// Run a benchmark when the given button is clicked and display results in the
// given element.
function benchOnClick(button, results, benchName, bencher) {
button.addEventListener(
"click",
async function(e) {
e.preventDefault();
const buttons = [...document.querySelectorAll("button")];
buttons.forEach(b => b.setAttribute("disabled", true));
results.innerHTML = "";
await new Promise(r => requestAnimationFrame(r));
var stats = await bencher();
buttons.forEach(b => b.removeAttribute("disabled"));
const csv = stats.xs
.map(x => `"${implAndBrowser}",${testSourceMap.mappings.length},"${benchName}",${x}`)
.join("\n");
results.innerHTML = `
<table>
<thead>
<tr>
<td>Samples</td>
<td>Total (${stats.unit})</th>
<td>Mean (${stats.unit})</th>
<td>Standard Deviation (${stats.unit})</th>
</tr>
</thead>
<tbody>
<tr>
<td>${stats.samples()}</td>
<td>${stats.total().toFixed(2)}</td>
<td>${stats.mean().toFixed(2)}</td>
<td>${stats.stddev().toFixed(2)}</td>
</tr>
</tbody>
</table>
<pre style="overflow:scroll;max-height:100px; max-width:500px;outline:1px solid black">${csv}</pre>
`;
},
false
);
}
for (let bench of Object.keys(benchmarks)) {
const hr = document.createElement("hr");
document.body.appendChild(hr);
const button = document.createElement("button");
button.innerHTML = `<h2>${bench}</h2>`;
document.body.appendChild(button);
const results = document.createElement("div");
document.body.appendChild(results);
benchOnClick(button, results, bench, benchmarks[bench]);
}