-
Notifications
You must be signed in to change notification settings - Fork 6
/
benchmark.html
44 lines (41 loc) · 1.36 KB
/
benchmark.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
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>benchmark</title>
</head>
<body>
<pre id="output"></pre>
<script type="module">
async function fetchScript (url) {
// for compatibility with Firefox
const re = /\b(export\s+(default\s+)?|import\s+Pianolizer\b[^\n]+)/gs
return fetch(url)
.then(response => response.text())
.then(text => text.replace(re, ''))
}
async function benchmark (library) {
return Promise.all([
fetchScript(library),
fetchScript('js/benchmark.js')
]).then(modules => {
const blob = new Blob(modules, { type: 'application/javascript' })
const worker = new Worker(URL.createObjectURL(blob), { type: 'module' })
return new Promise(resolve => {
worker.onmessage = e => resolve(e.data)
})
})
}
async function main () {
const output = document.getElementById('output')
output.innerText = window.navigator.userAgent
output.innerText += '\ntesting Pure JS...\n'
output.innerText += await benchmark('js/pianolizer.js')
output.innerText += '\ntesting WASM...\n'
output.innerText += await benchmark('js/pianolizer-wasm.js')
output.innerText += '\nfinished!'
}
main()
</script>
</body>
</html>