querySelector vs querySelectorAll vs getElementById vs getElementsByClassName vs getElementsByTagName vs getElementsByName

JavaScript performance comparison

Revision 90 of this test case created by

Preparation code

<section>
  <p id="foo" class="foo" name="fooname"></p>
  <span class="bar" name="barname">,,,</span>
  <a href="foo.com" target="_blank" title="foo"></a>
</section>
    

Preparation code output

<section> <p id="foo" class="foo" name="fooname"></p> <span class="bar" name="barname">,,,</span> <a href="foo.com" target="_blank" title="foo"></a> </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 TagName
document.querySelector("p");
pending…
querySelectorAll by tagName and multiple attributes
document.querySelector('a[href="foo.com"][target="_blank"][title="foo"]');
pending…
querySelectorAll by TagName
document.querySelectorAll("p")[0];
pending…
querySelector by ID
document.querySelector("#foo");
pending…
querySelector by Name
document.querySelector("[name=fooname]");
pending…
querySelectorAll by ClassName
document.querySelectorAll(".foo")[0];
pending…
getElementsByTagName
document.getElementsByTagName("p")[0];
pending…
querySelectorAll by Name
document.querySelectorAll("[name=fooname]")[0];
pending…
getElementsByName
document.getElementsByName("fooname")[0];
pending…
getElementsByClassName
document.getElementsByClassName("foo")[0];
pending…
querySelector by ClassName
document.querySelector(".foo");
pending…
querySelectorAll by ID
document.querySelectorAll("#foo")[0];
pending…
getElementById
document.getElementById("foo");
pending…

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL.

0 Comments

,,,