Created
May 19, 2019 12:07
-
-
Save Trshant/ad99e7bca9f0dbb83e0d4bd50334fa9d to your computer and use it in GitHub Desktop.
WA benchmarking
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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