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
This tests LocalStorage write performance, when there are storage event listeners. The test code is the same, the setUp and tearDown per test are different.
All subscribers use an empty callback, and exist within generated iFrames. (In general, storage events do not occur in the window setting a value.)
So the test is causing an exception when the iframes are added. I also can't tell how to perform asynchronous setups, to ensure the iframes are loaded.
Having said all that, given the negligible difference in the test results, I'd say the async nature of localStorage events, means any number of listeners may exist.
<style>
iframe.test {
display:none;
}
</style>
<script>
var iframeBox;
window.iframeHTML = '<s' + 'cript>' +
'window.addEventListener("storage", function () {parent.console.log("iframe saw this write")}, false);' +
'</s' + 'cript>';
function addSubscribers(cnt) {
var iframe;
iframeBox = document.createElement('div');
iframeBox.setAttribute('class', 'test');
while (cnt--) {
iframe = document.createElement('iframe');
iframe.src = 'javascript:parent.iframeHTML';
iframeBox.appendChild(iframe);
}
document.body.appendChild(iframeBox);
}
</script>
// 1 iframe
ui.benchmarks[1].setup = function () {
addSubscribers(1);
};
// 2 iframes
ui.benchmarks[2].setup = function () {
addSubscribers(2);
};
// 5 iframes
ui.benchmarks[3].setup = function () {
addSubscribers(5);
};
// 10 iframes
ui.benchmarks[4].setup = function () {
addSubscribers(10);
};
// 50 iframes
ui.benchmarks[5].setup = function () {
addSubscribers(50);
};
if (iframeBox) {
document.body.removeChild(iframeBox);
iframeBox = null;
}
localStorage.removeItem('foo');
Ready to run.
Test | Ops/sec | |
---|---|---|
Normal (no listeners) |
| ready |
1 listeners |
| ready |
2 listeners |
| ready |
5 listeners |
| ready |
10 listeners |
| ready |
50 listeners |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.