Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
moving childNodes from one parent node to another
moving childNodes from one parent node to another
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36
Browser:
Chrome 125
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
forEach loop childNodes
5142083.0 Ops/sec
for loop childNodes
10802636.0 Ops/sec
loop firstChild and append
13420899.0 Ops/sec
loop lastChild and prepend
13640937.0 Ops/sec
HTML Preparation code:
<html> <body></body> </html>
Script Preparation code:
const CHILDREN_COUNT = 1000; var containerDom = document.createElement('div'); for (var i = 0; i < CHILDREN_COUNT; i++) { containerDom.appendChild(document.createElement('span')); } document.body.appendChild(containerDom); var newContainerDom = document.createElement('div');
Tests:
forEach loop childNodes
const childNodes = containerDom.childNodes; childNodes.forEach(child => { newContainerDom.appendChild(child); });
for loop childNodes
const childNodes = containerDom.childNodes; for (let i = 0, len = childNodes.length; i < len; i++) { const child = childNodes[i]; newContainerDom.appendChild(child); }
loop firstChild and append
let firstChild = containerDom.firstChild; while (firstChild) { newContainerDom.appendChild(firstChild); firstChild = containerDom.firstChild; }
loop lastChild and prepend
let lastChild = containerDom.lastChild; while (lastChild) { newContainerDom.prependChild(lastChild); lastChild = containerDom.lastChild; }