Skip to content

Instantly share code, notes, and snippets.

@gskachkov
Created June 27, 2018 07:42
Show Gist options
  • Save gskachkov/185d9a21d77cab47903d5a6f83d441f8 to your computer and use it in GitHub Desktop.
Save gskachkov/185d9a21d77cab47903d5a6f83d441f8 to your computer and use it in GitHub Desktop.
let x = '../out/main.wasm';
let instance = null;
fetch(x).then(response =>
response.arrayBuffer()
).then(bytes =>
WebAssembly.instantiate(bytes, {
env: {
add_js: (a, b) => a + b
}
})
).then(results => {
instance = results.instance;
const arr = [];
const start = performance.now();
for (var i = 0; i < 1000000; i++) {
arr.push(instance.exports.fibonacci_wasm(45));
}
document.getElementById("container").innerText = arr[ arr.length - 1 ] + ":" + ( performance.now() - start );
}).catch(console.error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment