HTML Preparation code:
AخA
 
1
<div id='x'></div>
Script Preparation code:
x
 
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);
}
Tests:
  • innerHTML

     
    const root = document.getElementById('x').cloneNode(true);
    root.innerHTML = '';
  • removeChild firstChild

     
    const root = document.getElementById('x').cloneNode(true);
    while (root.firstChild)
        root.removeChild(root.firstChild);
  • removeChild lastChild

     
    const root = document.getElementById('x').cloneNode(true);
    while (root.lastChild)
        root.removeChild(root.lastChild);
  • textContent

     
    const root = document.getElementById('x').cloneNode(true);
    root.textContent = '';
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    innerHTML
    removeChild firstChild
    removeChild lastChild
    textContent

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 2 years ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36
Chrome 104 on Windows
View result in a separate tab
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