Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
replaceChildren VS while+appendChild VS replaceChildren+fragment VS innerHTML+fragment VS while+fragment
replaceChildren VS while+appendChild VS replaceChildren+fragment VS innerHTML+fragment VS while+fragment
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:126.0) Gecko/20100101 Firefox/126.0
Browser:
Firefox 126
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
replaceChildren w/ fragments
139/s
replaceChildren
136/s
innerHTML w/ fragments
93/s
while w/ fragments
88/s
while w/ appendChild
84/s
View exact numbers
Test name
Executions per second
✓
replaceChildren w/ fragments
139 Ops/sec
replaceChildren
136 Ops/sec
innerHTML w/ fragments
93 Ops/sec
while w/ fragments
88 Ops/sec
while w/ appendChild
84 Ops/sec
HTML Preparation code:
<div id="container"></div>
Script Preparation code:
const node = document.getElementById('container'); for(let i = 0; i < 10000; i++) { node.appendChild(document.createElement('div')); }
Tests:
replaceChildren
const node = document.getElementById('container'); const elems = []; for(let i = 0; i < 10000; i++) { elems.push(document.createElement('div')); } node.replaceChildren(...elems);
while w/ appendChild
const node = document.getElementById('container'); const elems = []; for(let i = 0; i < 10000; i++) { elems.push(document.createElement('div')); } while (node.firstChild) { node.removeChild(node.lastChild); } for(let i = 0; i < 10000; i++) { node.appendChild(elems[i]); }
replaceChildren w/ fragments
const fragment = document.createDocumentFragment(); const node = document.getElementById('container'); const elems = []; for(let i = 0; i < 10000; i++) { elems.push(document.createElement('div')); } for(let i = 0; i < 10000; i++) { fragment.appendChild(elems[i]); } node.replaceChildren(fragment);
innerHTML w/ fragments
const fragment = document.createDocumentFragment(); const node = document.getElementById('container'); const elems = []; for(let i = 0; i < 10000; i++) { elems.push(document.createElement('div')); } for(let i = 0; i < 10000; i++) { fragment.appendChild(elems[i]); } node.innerHTML = ''; node.appendChild(fragment);
while w/ fragments
const fragment = document.createDocumentFragment(); const node = document.getElementById('container'); const elems = []; for(let i = 0; i < 10000; i++) { elems.push(document.createElement('div')); } for(let i = 0; i < 10000; i++) { fragment.appendChild(elems[i]); } while (node.firstChild) { node.removeChild(node.lastChild); } node.appendChild(fragment);