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
<div id="root"></div>
let list = [...Array(1000).keys()];
function withoutDelegation() {
list.forEach(item => {
let div = document.createElement('div');
div.innerHTML = item;
div.classList.add('item');
div.addEventListener('click', (e) => {
alert(e.target.innerHTML);
});
document.getElementById('root').appendChild(div);
});
}
function withDelegation() {
list.forEach(item => {
let div = document.createElement('div');
div.innerHTML = item;
div.classList.add('item');
document.getElementById('root').appendChild(div);
});
document.getElementById('root').addEventListener('click', (e) => {
if (e.target.classList.contains('item')) {
alert(e.target.innerHTML);
}
});
}
Ready to run.
Test | Ops/sec | |
---|---|---|
without delegation |
| ready |
with delegation |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.