Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:108.0) Gecko/20100101 Firefox/108.0
Firefox 108
Windows
Desktop
one year ago
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 Preparation code:
x
 
1
<html>
2
3
<body>
4
    <div id='test'>
5
        <div name='a'></div>
6
        <div name='b'></div>
7
        <div name='c'></div>
8
    </div>
9
</body>
10
11
</html>
Script Preparation code:
 
var parent = document.getElementById('test');
Tests:
  • childNodes

     
    parent.childNodes.forEach(function (node) {
      let n = node;
    });
  • children

     
    for (let i = 0; i < parent.children.length; i++) {
      let n = parent.children[i];
    }
  • firstChild nextSibling

     
    let elem = parent.firstChild;
    do {
      let n = elem;
    } while (elem = elem.nextSibling)
  • firstElementChild nextElementChild

     
    let elem = parent.firstElementChild;
    do {
      let n = elem;
    } while (elem = elem.nextElementSibling)
  • ChildNodes2

     
    let children = parent.childNodes;
    for (let i = 0; i < children.length; i++) {
      let n = children[i];
    }