Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
replaceChild vs replaceChildren vs documentFragment more nodes
(version: 1)
Comparing performance of:
replaceChild vs replaceChildren vs append documentFragment
Created:
one year ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<div id="container"></div>
Script Preparation code:
var elements = [document.createElement('div'), document.createElement('div'),document.createElement('div'), document.createElement('div'),document.createElement('div'), document.createElement('div'), document.createElement('div'), document.createElement('div')]; var fragment = document.createDocumentFragment(); var container = document.getElementById('container'); elements.forEach(element => fragment.appendChild(element)); container.appendChild(fragment);
Tests:
replaceChild
var changeIndex = 1; elements[changeIndex] = document.createElement('div'); container.replaceChild(elements[changeIndex], container.children[changeIndex]);
replaceChildren
var changeIndex = 1; elements[changeIndex] = document.createElement('div'); container.replaceChildren(elements)
append documentFragment
var changeIndex = 1; var newChildren = document.createDocumentFragment(); elements[changeIndex] = document.createElement('div'); elements.forEach(element => newChildren.appendChild(element)); while(container.firstChild) { container.firstChild.remove(); } container.appendChild(newChildren)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
replaceChild
replaceChildren
append documentFragment
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
replaceChild
2321757.8 Ops/sec
replaceChildren
623221.1 Ops/sec
append documentFragment
437948.7 Ops/sec
Related benchmarks:
CloneNode after Append to Fragment vs Append to DOM
Cherrypick replace child vs appending a document fragment
replaceChild vs replaceChildren vs documentFragment
replaceWith vs replaceChild without iframe
replaceChild vs replaceChildren vs documentFragment 2
replaceChild vs replaceChildren vs documentFragment 3
replaceChildren vs documentFragment [2]
replaceChildren vs while w/ appendChild
replaceChildren vs document fragment
Comments
Confirm delete:
Do you really want to delete benchmark?