querySelector vs querySelectorAll vs getElementById vs getElementsByClassName vs getElementsByTagName vs getElementsByName (scope by form)

JavaScript performance comparison

Revision 54 of this test case created

Preparation code

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

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
querySelector by ID
document.forms['test'].querySelector("#foo");
pending…
querySelectorAll by ID
document.forms['test'].querySelectorAll("#foo")[0];
pending…
getElementById
document.forms['test'].getElementById("foo");
pending…
getElementsByClassName
document.forms['test'].getElementsByClassName("foo")[0];
pending…
getElementsByTagName
document.forms['test'].getElementsByTagName("p")[0];
pending…
getElementsByName
document.forms['test'].getElementsByName("fooname")[0];
pending…
querySelector by ClassName
document.forms['test'].querySelector(".foo");
pending…
querySelectorAll by ClassName
document.forms['test'].querySelectorAll(".foo")[0];
pending…
querySelector by TagName
document.forms['test'].querySelector("p");
pending…
querySelectorAll by TagName
document.forms['test'].querySelectorAll("p")[0];
pending…
querySelector by Name
document.forms['test'].querySelector("[name=fooname]");
pending…
querySelectorAll by Name
document.forms['test'].querySelectorAll("[name=fooname]")[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. Here’s a list of current revisions for this page:

0 comments

Add a comment