jQuery selector vs built-in selector wrapped in jQuery

JavaScript performance comparison

Revision 83 of this test case created by Henry Zou

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<p id="bar" class="my-bar">
  Bar
</p>
<div id="poo" class="my-poo">
  <div id="par" class="my-bar">
    <div id="paz" class="my-bar">
      <span id="baz" class="my-baz">
        Baz
      </span>
    </div>
  </div>
</div>
    

Preparation code output

<p id="bar" class="my-bar"> Bar </p> <div id="poo" class="my-poo"> <div id="par" class="my-bar"> <div id="paz" class="my-bar"> <span id="baz" class="my-baz"> Baz </span> </div> </div> </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
jQuery ClassSelector with find
var baz = $("div").filter(function(item){
return $(item).hasClass("my-poo");
});
pending…
querySelector (Class)
var baz = document.querySelector("div.my-poo");
pending…
jQuery ClassSelector
var baz = $("div.my-poo");
pending…
querySelector (ID)
var bar = document.querySelector("#poo");
pending…
jQuery ID Selector
var bar = $("#poo");
pending…
getElementById
var bar = document.getElementById("poo");
pending…
querySelector (ID) wrap in jQuery
var bar = $(document.getElementById("poo"))
pending…
querySelector (Class) wrap in jQuery
var baz = $(document.querySelector("div.my-poo"));
pending…
querySelector (Class) wrap in jQuery
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

Bar

Baz