querySelectorAll vs getElementsByTagName

JavaScript performance comparison

Revision 17 of this test case created

Preparation code

<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 makeArray(obj) {
   var arr = [];
   for (var i = obj.length; i--;)
   arr[i] = obj[i];
   return arr;
  }
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
querySelectorAll
var nodes = document.querySelectorAll('a')
pending…
byTagName live
var nodes = document.getElementsByTagName('a')
pending…
byTagName static
var nodes = makeArray(document.getElementsByTagName('a'));
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment