nextSibling vs indexed childNodes (v3)

Revision 3 of this benchmark created on


Description

We want to check nextSibling iteretion vs indexed iteretion in Array

Preparation HTML

<div id="test"/>
<script>
  var divContainer = document.getElementById("test");
  for (var i = 0; i < 1000; i++) {
   var div = document.createElement('div');
   divContainer.appendChild(div);
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
nextSibling
let child = document.getElementById("test").firstChild;
while (child = child.nextSibling) {}
ready
childNodes
const children = document.getElementById("test").childNodes;
let z = 0
for (let ch = children[z]; !!ch; z++) {
 ch = children[z];
}
ready
reverse iteration childNodes
const childr = document.getElementById("test").childNodes;
let w = childr.length;
while (w--) {
 const chi = childr[w];
}
ready
previousSibling
let child = document.getElementById("test").lastChild;
while (child = child.previousSibling) {}
ready

Revisions

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

  • Revision 1: published by Sergey Babinsky on
  • Revision 3: published on