NodeList vs. array iteration (v3)

Revision 3 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;
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Live List
var liveList = document.getElementsByTagName('a');
for (var i = 0, length = liveList.length; i < length; i++) {
 liveList[i].nodeName;
}
ready
Static List
var statList = document.querySelectorAll('a');
for (var i = 0, length = statList.length; i < length; i++) {
 statList[i].nodeName;
}
ready
Array of Live List
var liveArr = toArray(document.getElementsByTagName('a'));
for (var i = 0, length = liveArr.length; i < length; i++) {
 liveArr[i].nodeName;
}
ready
Array of Static List
var statArr = toArray(document.querySelectorAll('a'));
for (var i = 0, length = statArr.length; 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.