nextSibling vs indexed childNodes

Benchmark created by Sergey Babinsky 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
var child = document.getElementById("test").firstChild;
var y = 0;
while (child = child.nextSibling) {
 y++;
}
ready
childNodes
var children = document.getElementById("test").childNodes;
var length = children.length;
for (var z = 0; z < length; z++) {
 var ch = children[z];
}
ready
reverse iteration childNodes
var childr = document.getElementById("test").childNodes;
var w = childr.length;
var chi;
while (w--) {
 chi = childr[w];
}
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