Skip to content

Instantly share code, notes, and snippets.

@Trshant
Created May 19, 2019 12:07
Show Gist options
  • Save Trshant/ad99e7bca9f0dbb83e0d4bd50334fa9d to your computer and use it in GitHub Desktop.
Save Trshant/ad99e7bca9f0dbb83e0d4bd50334fa9d to your computer and use it in GitHub Desktop.
WA benchmarking
<html>
<head>
<script>
let squarer;
function loadWebAssembly(fileName) {
return fetch(fileName)
.then(response => response.arrayBuffer())
.then(bits => WebAssembly.compile(bits))
.then(module => { return new WebAssembly.Instance(module) });
};
loadWebAssembly('example.wasm')
.then(instance => {
squarer = instance.exports._Z7squareri;
console.log('Finished compiling! Ready when you are...');
});
function time_my_script(script) {
var start = new Date();
script();
return new Date() - start;
}
function js_squarer(num) {
return num * num;
}
function check(){
time = time_my_script(function() {
for (i = 0; i <= 1000000000; i++) {
squarer(27);
}
});
console.log( "1 : "+time );
time2 = time_my_script(function () {
for (i = 0; i <= 1000000000; i++) {
js_squarer(27);
}
});
console.log( "2 : " +time2 );
}
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment