querySelector id vs class vs element vs attribute version 2

JavaScript performance comparison

Revision 43 of this test case created by

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
var i, $p = $('p');
for (i = 0; i < 50; i++)
$p.append('<span></span>');
</script>
<div>
  <p>
    <span id="id" class="class" data-attribute="attribute">
      Content
    </span>
  </p>
</div>
    

Preparation code output

<script> var i, $p = $('p'); for (i = 0; i < 50; i++) $p.append('<span></span>'); </script> <div> <p> <span id="id" class="class" data-attribute="attribute"> Content </span> </p> </div>

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 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 attribute no value
document.querySelector("[data-attribute]");
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

Content