querySelector vs querySelectorAll vs getElementById vs getElementsByClassName vs getElementsByTagName vs getElementsByName

JavaScript performance comparison

Revision 51 of this test case created by

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<section>
  <p id="foo" class="foo" name="fooname"></p>
  <span class="bar" name="barname">,,,</span>
</section>
    

Preparation code output

<section> <p id="foo" class="foo" name="fooname"></p> <span class="bar" name="barname">,,,</span> </section>

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 by ID
document.querySelector("#foo");
pending…
querySelectorAll by ID
document.querySelectorAll("#foo")[0];
pending…
getElementById
document.getElementById("foo");
pending…
getElementsByClassName
document.getElementsByClassName("foo")[0];
pending…
getElementsByTagName
document.getElementsByTagName("p")[0];
pending…
getElementsByName
document.getElementsByName("fooname")[0];
pending…
querySelector by ClassName
document.querySelector(".foo");
pending…
querySelectorAll by ClassName
document.querySelectorAll(".foo")[0];
pending…
querySelector by TagName
document.querySelector("p");
pending…
querySelectorAll by TagName
document.querySelectorAll("p")[0];
pending…
querySelector by Name
document.querySelector("[name=fooname]");
pending…
querySelectorAll by Name
document.querySelectorAll("[name=fooname]")[0];
pending…
jQuery id
$("#foo")[0]
pending…
jQuery class
$(".foo")[0]
pending…
jQuery name
$("[name=fooname]")[0]
pending…
jquery element
$("p")[0]
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

,,,