querySelector vs querySelectorAll vs getElementById vs getElementsByClassName vs getElementsByTagName

JavaScript performance comparison

Revision 38 of this test case created

Preparation code

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

Preparation code output

bar

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
querySelector
document.querySelector("#foo");
pending…
querySelectorAll
document.querySelectorAll("#foo")[0];
pending…
getElementById
document.getElementById("foo");
pending…
getElementsByClassName
document.getElementsByClassName("foo")[0];
pending…
getElementsByTagName
document.getElementsByTagName("p");
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