querySelectorAll vs getElementsByTagName

JavaScript performance comparison

Revision 92 of this test case created by Yaroslaff Fedin

Preparation code

<div id="id">
  <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() {
    d = document.getElementById('id')
};
</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 = d.querySelectorAll('a')
pending…
getElementsByTagName
var nodes = d.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