HTML Preparation code:
AخA
 
1
<div id="container"></div>
Script Preparation code:
x
 
const node = document.getElementById('container');
const fragment = document.createDocumentFragment();
for(let i = 0; i < 10000; i++) {
    node.appendChild(document.createElement('div'));
    fragment.appendChild(document.createElement('div'));
}
Tests:
  • while w/ appendChild

     
    const node = document.getElementById('container');
    const fragment = document.createDocumentFragment();
    for(let i = 0; i < 10000; i++) {
        fragment.appendChild(document.createElement('div'));
    }
    while (node.firstChild) {
        node.removeChild(node.lastChild);
    }
    node.appendChild(fragment);
  • replaceChildren

     
    const node = document.getElementById('container');
    const fragment = document.createDocumentFragment();
    for(let i = 0; i < 10000; i++) {
        fragment.appendChild(document.createElement('div'));
    }
    node.replaceChildren(fragment);
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    while w/ appendChild
    replaceChildren

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 10 months ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36
Chrome 125 on Windows
View result in a separate tab
Test name Executions per second
while w/ appendChild 118.3 Ops/sec
replaceChildren 138.5 Ops/sec