Last active
February 18, 2018 12:47
-
-
Save tkihira/aebed3a3ee34cc0ca6e8aecba0c073a8 to your computer and use it in GitHub Desktop.
This file contains 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><title>WebAssembly: JavaScript binding profiling</title> | |
<script> | |
onload = function() { | |
var textarea = document.getElementById("textarea"); | |
var log = function(message) { | |
var now = performance.now(); | |
textarea.value += (now - time).toFixed(3) + ": " + message + "\n"; | |
time = performance.now(); | |
}; | |
var time = performance.now(); | |
var c = 0; | |
var importObj = { | |
test: { | |
jsf: function() { | |
c++; | |
} | |
} | |
}; | |
var profiling = function(filename) {; | |
log(filename + ": download start"); | |
fetch(filename).then(function(response) { | |
log("download end"); | |
return response.arrayBuffer() | |
}).then(function(bytes) { | |
log("compile start"); | |
return WebAssembly.compile(bytes); | |
}).then(function(module) { | |
log("compile end / instantiate start"); | |
return WebAssembly.instantiate(module, importObj); | |
}).then(function(result) { | |
log("instantiate end / fib calc start"); | |
var test = result.exports.fib; | |
log("result:" + test(40)); | |
if(c) { | |
log("called JavaScript function " + c + " times"); | |
} else { | |
profiling("fib_binding.wasm"); | |
} | |
log("--------------------------"); | |
}); | |
}; | |
profiling("fib.wasm"); | |
} | |
</script> | |
</head><body><textarea id="textarea" cols="80" rows="20"></textarea></body></html> |
This file contains 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