jQuery selector vs built-in selector wrapped in jQuery (v83)

Revision 83 of this benchmark created by Henry Zou on


Description

Changes to rev 26 (rev 27 is worse):
- repositioning xpath
- remove foo + checks for it (search for selecting elem by id once is enough)
- remove getElementById("poo") in querySelector (Class) & jQuery Class Selector for a true comparison of the algorithms.
- jQuery Class Selector -> jQuery w. querySelector
- added real jQuery ClassSelector

Preparation HTML

<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>

Test runner

Ready to run.

Testing in
TestOps/sec
getElementById
var bar = document.getElementById("poo");
ready
querySelector (ID)
var bar = document.querySelector("#poo");
ready
jQuery ID Selector
var bar = $("#poo");
ready
querySelector (Class)
var baz = document.querySelector("div.my-poo");
 
ready
jQuery ClassSelector
var baz = $("div.my-poo");
ready
jQuery ClassSelector with find
var baz = $("div").filter(function(item){
return $(item).hasClass("my-poo");
});
ready
querySelector (ID) wrap in jQuery
var bar = $(document.getElementById("poo"))
ready
querySelector (Class) wrap in jQuery
var baz = $(document.querySelector("div.my-poo"));
 
ready
querySelector (Class) wrap in jQuery
 
ready

Revisions

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