querySelector id vs class vs element vs attribute version 3

JavaScript performance comparison

Revision 23 of this test case created

Preparation code

<div>
  <p>
    <span id="id" class="class class2" data-attribute="attribute">
      Content
    </span>
  </p>
</div>

Preparation code output

Content

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 id
document.querySelector("#id");
pending…
queryselector class
document.querySelector(".class");
pending…
querySelector attribute
document.querySelector("[data-attribute='attribute']");
pending…
querySelector element
document.querySelector("span");
pending…
querySelector element / class
document.querySelector("span.class");
pending…
querySelector element / attribute
document.querySelector("span[data-attribute='attribute']");
pending…
querySelector class / attribute
document.querySelector(".class[data-attribute='attribute']");
pending…
querySelector element / class / attribute
document.querySelector("span.class[data-attribute='attribute']");
pending…
querySelector class / class
document.querySelector(".class.class2");
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