Edge Promise Performance
Measures performance of Edge promises.
HTML
<pre><code id="status">Running...</code></pre>
JavaScript
// replace setTimeout with an implementation that counts it's invocations.
var timeouts = 0;
var _setTimeout = window.setTimeout.bind(window);
window.setTimeout = function(f, t) {
timeouts++;
return _setTimeout(f, t);
};
// track the start time.
var start = performance.now();
function displayResult() {
var end = performance.now();
var status = document.querySelector('#status');
status.textContent += ' done.\n';
status.textContent += (end - start).toString(10) + 'ms elapsed.\n';
status.textContent += 'setTimeout called ' + timeouts.toString(10) + ' times.';
}
// chain up some promises...
var i = 1000;
var p = new Promise(function(resolve, reject) { resolve(); });
while (i--) {
p = p.then(function(resolve, reject) { return 'done'; });
}
p.then(displayResult);