nextSibling vs childNodes (v21)

Revision 21 of this benchmark created by Peter 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>

Setup

var container = document.getElementById('container');
    var result = [];

Test runner

Ready to run.

Testing in
TestOps/sec
nextSibling
var node = container.firstChild;
while (node) {
 result.push(node);
 node = node.nextSibling;
}
ready
nextElementSibling
var node = container.firstElementChild;
while (node) {
 result.push(node);
 node = node.nextElementSibling;
}
ready

Revisions

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