querySelectorAll vs getElementsByTagName (v74)

Revision 74 of this benchmark created by Dan 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>
<a href="#"><span>Hello</span></a>
<strong>Bold!</strong>
</div>

Test runner

Ready to run.

Testing in
TestOps/sec
querySelectorAll
var nodes = document.querySelectorAll('*')
ready
getElementsByTagName
 
ready
getElementsByTagName, converted to static list
var nodes = [];
var liveNodes = document.getElementsByTagName('*');
for(var i = 0, length = liveNodes.length; i < length; ++i)
    nodes.push(liveNodes[i]);
 
ready
getElementsByTagName, converted to static list 2
//Seems to work, but the spec offers no guarantee of array functions working on NodeLists
var nodes = Array.prototype.slice.call(document.getElementsByTagName('*'));
ready

Revisions

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