jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
set immediate test
<script>
setTimeout(function () {
if (!window.setImmediate) {
ui.benchmarks[0].options.defer = false;
}
if (!window.msSetImmediate) {
ui.benchmarks[2].options.defer = false;
}
if (!window.MessageChannel) {
ui.benchmarks[3].options.defer = false;
} else {
window.immediateChannel = new MessageChannel();
}
if ("onreadystatechange" in document.createElement("script")) {
window.readyStateChange = true;
} else {
ui.benchmarks[4].options.defer = false;
}
if (!window.postMessage || (Number(Benchmark.platform.version)<=8 && Benchmark.platform.name === 'IE') ) {
ui.benchmarks[5].options.defer = false;
ui.benchmarks[7].options.defer = false;
} else {
window.immediateCallbacks = {};
var onGlobalMessage = function (event) {
if (event.data.indexOf('immediate') === 0) {
var handle = 'h' + event.data.substring(9);
immediateCallbacks[handle]();
delete immediateCallbacks[handle];
}
};
if (window.addEventListener) {
window.addEventListener("message", onGlobalMessage, false);
} else {
window.attachEvent("onmessage", onGlobalMessage);
}
}
if ( !window.requestAnimationFrame) {
ui.benchmarks[6].options.defer = false;
}
if ( !window.MutationObserver ) {
ui.benchmarks[8].options.defer = false;
}
else {
window.setImmediateM = (function() {
var hiddenDiv = document.createElement("div");
var callbacks = [];
(new MutationObserver(function(records) {
var cbList = callbacks.slice();
callbacks.length = 0;
cbList.forEach(function(callback) { callback(); });
})).observe(hiddenDiv, { attributes: true });
return function setImmediate(callback) {
if( !callbacks.length) {
hiddenDiv.setAttribute('yes', 'no');
}
callbacks.push(callback);
};
})();
}
}, 0);
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
setImmediate |
| ready |
setTimeout |
| ready |
msSetImmediate |
| ready |
MessageChannel |
| ready |
readyStateChange |
| ready |
postMessage |
| ready |
requestAnimationFrame |
| ready |
image + data-url |
| ready |
MutationObserver |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.