This repository has been archived by the owner on Nov 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
76 lines (66 loc) · 1.8 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
<!doctype html>
<!-- https://raw.githubusercontent.com/golang/go/release-branch.go1.12/misc/wasm/wasm_exec.html -->
<!--
Copyright 2018 The Go Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
-->
<html>
<head>
<meta charset="utf-8">
<title>Monte Carlo PI Estimation Benchmark</title>
</head>
<body>
<!-- JavaScript -->
<script src="src/mcpi.js"></script>
<script>
function runJs() {
calcMcpi();
}
</script>
<!-- Go -->
<script src="wasm_exec.js"></script>
<script>
if (!WebAssembly.instantiateStreaming) { // polyfill
WebAssembly.instantiateStreaming = async (resp, importObject) => {
const source = await (await resp).arrayBuffer();
return await WebAssembly.instantiate(source, importObject);
};
}
const go = new Go();
let mod, inst;
WebAssembly.instantiateStreaming(fetch("mcpi-go.wasm"), go.importObject).then((result) => {
mod = result.module;
inst = result.instance;
}).catch((err) => {
console.error(err);
});
async function runGo() {
await go.run(inst);
inst = await WebAssembly.instantiate(mod, go.importObject); // reset instance
}
</script>
<!-- C++ -->
<script src="mcpi-cpp.js"></script>
<script>
function runCpp() {
_main();
}
</script>
<h1>Monte Carlo PI Estimation Benchmark</h1>
<button onClick="runJs();" id="runButtonJs">JavaScript</button><br>
<div id="resultJS"></div>
<br>
<button onClick="runGo();" id="runButton">Go</button><br>
<div id="resultGo"></div>
<br>
<button onClick="runCpp();" id="runButtonCpp">C/C++</button><br>
<div id="resultCpp"></div>
<br>
<iframe id="versionInfo" src='info.txt' scrolling='no'></iframe>
<footer>
<br>
<a href="https://github.com/ebiiim/wasm-pi-microbench">source code</a>
</footer>
</body>
</html>