Test name | Executions per second |
---|---|
childNodes | 1657590.6 Ops/sec |
children | 1964699.6 Ops/sec |
firstChild nextSibling | 4071400.2 Ops/sec |
firstElementChild nextElementChild | 13604771.0 Ops/sec |
ChildNodes2 | 1613444.0 Ops/sec |
<html>
<body>
<div id='test'>
<div name='a'></div>
<div name='b'></div>
<div name='c'></div>
</div>
</body>
</html>
var parent = document.getElementById('test');
parent.childNodes.forEach(function (node) {
let n = node;
});
for (let i = 0; i < parent.children.length; i++) {
let n = parent.children[i];
}
let elem = parent.firstChild;
do {
let n = elem;
} while (elem = elem.nextSibling)
let elem = parent.firstElementChild;
do {
let n = elem;
} while (elem = elem.nextElementSibling)
let children = parent.childNodes;
for (let i = 0; i < children.length; i++) {
let n = children[i];
}