querySelectorAll vs getElementsByTagName (v76)

Revision 76 of this benchmark created by attr vs class on


Preparation HTML

<div>
  <ul>
    <li><a href="#">item 1</a></li>
    <li><a class="foo" href="#">item 2</a></li>
    <li><a href="#">item 3</a></li>
  </ul>
</div>

Test runner

Ready to run.

Testing in
TestOps/sec
querySelectorAll
var nodes = document.querySelectorAll('a.foo')
ready
getElementsByTagName
var result = document.getElementsByTagName('a'),
    nodes = [];
for (var i = 0, len = result.length; i < len; i++) {
  if (result[i].className.indexOf('foo') !== -1) {
    nodes.push(result[i]);
  }
}
 
ready

Revisions

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