querySelector vs querySelectorAll vs getElementById vs getElementsByClassName vs getElementsByTagName

JavaScript performance comparison

Revision 68 of this test case created by

Preparation code

<p id="foo" class="foo">
  bar

<ul>
   <li><a href="#">Page 1</a></li>
   <li><a href="#">Page 2</a></li>
   <li><a href="#">Page 3</a></li>
   <li><a href="#">Page 4</a></li>
</ul>

</p>
    

Preparation code output

<p id="foo" class="foo"> bar <ul> <li><a href="#">Page 1</a></li> <li><a href="#">Page 2</a></li> <li><a href="#">Page 3</a></li> <li><a href="#">Page 4</a></li> </ul> </p>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
querySelector
document.querySelector("#foo a");
pending…
querySelectorAll
document.getElementById('foo').querySelectorAll("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.

0 Comments

bar