querySelectorAll vs getElementsByTagName

JavaScript performance comparison

Revision 34 of this test case created

Info

Trying to force a lookup of the nodeList by adding .length

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>
Benchmark.prototype.setup = function() {
    var ul = document.querySelector('ul');
};
</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'),
nodelength = nodes.length;
pending…
getElementsByTagName
var nodes = document.getElementsByTagName('a'),
nodelength = nodes.length;
pending…
localized querySelectorAll
var nodes = ul.querySelectorAll('a'),
nodelength = nodes.length;
pending…
localized getElementsByTagName
var nodes = ul.getElementsByTagName('a'),
nodelength = nodes.length;
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