nextSibling vs childNodes (v25)

Revision 25 of this benchmark created on


Description

Test the relative performance of iterating through child nodes using nextSibling vs iterating through the childNodes array.

Preparation HTML

<div id="container">
<p>Child</p>
<p>Child</p>
<p>Child</p>
<p>Child</p>
<p>Child</p>
<p>Child</p>
<p>Child</p>
<p>Child</p>
<p>Child</p>
<p>Child</p>
</div>
<script>
  var container = document.getElementById('container');
  
  function process(element) {}
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
childNodes
process(container.childNodes[9]);
 
ready
childNodes, cached
var nodes = container.childNodes;

 process(nodes[9]);
 
ready
nextSibling
var node = container.firstChild, i = 0;
while (i !== 9) {
 node = node.nextSibling;
 i++;
}
process(node);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.