querySelector id vs class vs element vs attribute version 3 (v23)

Revision 23 of this benchmark created on


Preparation HTML

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

Test runner

Ready to run.

Testing in
TestOps/sec
queryselector id
document.querySelector("#id");
ready
queryselector class
document.querySelector(".class");
ready
querySelector attribute
document.querySelector("[data-attribute='attribute']");
ready
querySelector element
document.querySelector("span");
ready
querySelector element / class
document.querySelector("span.class");
ready
querySelector element / attribute
document.querySelector("span[data-attribute='attribute']");
ready
querySelector class / attribute
document.querySelector(".class[data-attribute='attribute']");
ready
querySelector element / class / attribute
document.querySelector("span.class[data-attribute='attribute']");
ready
querySelector class / class
document.querySelector(".class.class2");
ready

Revisions

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