NodeList vs. array iteration (v4)

Revision 4 of this benchmark created on


Preparation HTML

<div>
  <ul>
    <li><a href="#">item 1</a></li>
    <li><a href="#">item 2</a></li>
    <li><a href="#">item 3</a></li>
  </ul>
</div>
<script>
  function toArray(collection) {
   var result = [],
       i = -1;
   while (result[++i] = collection[i]) {};
   result.length--;
   return result;
  }
  
  var liveList = document.getElementsByTagName('a');
  var statList = document.querySelectorAll('a');
  var liveArr = toArray(liveList);
  var statArr = toArray(statList);
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Live List
var length = liveList.length
    , i;
for (i = 0; i < length; i++) {
 liveList[i].nodeName;
}
ready
Static List
var length = statList.length
    , i;
for (i = 0 ; i < length; i++) {
 statList[i].nodeName;
}
ready
Array of Live List
var length = liveArr.length
    , i;
for (i = 0; i < length; i++) {
 liveArr[i].nodeName;
}
ready
Array of Static List
var length = statArr.length
    , i;
for (i = 0; i < length; i++) {
 statArr[i].nodeName;
}
ready

Revisions

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