querySelectorAll vs getElementsByTagName (v48)

Revision 48 of this benchmark created by Adam 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>

Setup

var G = function(item) {  console.log(item);
      // if its an id alert
      if (item[0] === '#')
          return document.getElementById(item.slice(1));
      // if class alert
      else if (item[0] === '.')
          return document.getElementsByClassName(item.slice(1));
      else
         return document.getElementsByTagName(item);
    };

Test runner

Ready to run.

Testing in
TestOps/sec
querySelectorAll
var nodes = document.querySelectorAll('a')
ready
getElementsByTagName
var nodes = document.getElementsByTagName('a')
ready
var nodes = G('a')
ready

Revisions

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