-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_montecarlo.html
More file actions
38 lines (33 loc) · 1.21 KB
/
test_montecarlo.html
File metadata and controls
38 lines (33 loc) · 1.21 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test Monte Carlo</title>
<script src="example/public/wasm_exec.js"></script>
</head>
<body>
<h1>Monte Carlo Test</h1>
<button onclick="testPi()">Test Pi Estimation</button>
<pre id="result"></pre>
<script>
async function loadWasm() {
const go = new Go();
const response = await fetch('example/public/main.wasm');
const buffer = await response.arrayBuffer();
const result = await WebAssembly.instantiate(buffer, go.importObject);
go.run(result.instance);
await new Promise(resolve => setTimeout(resolve, 200));
}
function testPi() {
console.log('Testing monteCarlo function...');
console.log('Function exists?', typeof window.monteCarlo);
const result = window.monteCarlo('pi', 100000);
console.log('Result:', result);
document.getElementById('result').textContent = JSON.stringify(result, null, 2);
}
loadWasm().then(() => {
console.log('WASM loaded, monteCarlo function:', typeof window.monteCarlo);
});
</script>
</body>
</html>