Created
August 3, 2017 22:15
-
-
Save nolanlawson/ee1222ee2acf9756f7457fb01beac6ae to your computer and use it in GitHub Desktop.
Promise throughput test
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
<!doctype html> | |
<html> | |
<button type=button onclick="runTest()">Run test</button> | |
<pre id=display></pre> | |
<script> | |
function runTest() { | |
performance.mark('start') | |
var p = Promise.resolve() | |
for (var i = 0; i < 10000; i++) { | |
p = p.then(function() { return 'done'; }) | |
} | |
p.then(function () { | |
performance.mark('finish') | |
performance.measure('time', 'start', 'finish') | |
display.innerHTML += `Time: ${performance.getEntriesByType('measure').slice(-1)[0].duration}ms\n` | |
}) | |
} | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment