Test name | Executions per second |
---|---|
innerHTML | 10131.4 Ops/sec |
removeChild firstChild | 6893.2 Ops/sec |
removeChild lastChild | 6915.7 Ops/sec |
textContent | 11305.0 Ops/sec |
<div id='x'></div>
const root = document.getElementById('x');
for (let i = 0; i < 100; i++) {
let notRoot = document.createElement('div')
notRoot.innerHTML = `the rainbow eats sunlight under jupiter's moonlight ${Math.random()}`;
root.appendChild(notRoot);
}
const root = document.getElementById('x').cloneNode(true);
root.innerHTML = '';
const root = document.getElementById('x').cloneNode(true);
while (root.firstChild)
root.removeChild(root.firstChild);
const root = document.getElementById('x').cloneNode(true);
while (root.lastChild)
root.removeChild(root.lastChild);
const root = document.getElementById('x').cloneNode(true);
root.textContent = '';