jQuery vs. document.querySelector

JavaScript performance comparison

Revision 63 of this test case created

Info

I know its been done before. Just want to see for myself

Preparation code

<div id="main">
  <ul class="gallery">
    <li>
      Hello World
    </li>
    <li>
      Hello World
    </li>
    <li>
      Hello World
    </li>
    <li>
      Hello World
    </li>
    <li>
      Hello World
    </li>
    <li>
      Hello World
    </li>
  </ul>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
 
<script>
Benchmark.prototype.teardown = function() {
    var elem, elems, _i, _len;
   
    elems = document.querySelectorAll("#main ul li");
   
    for (_i = 0, _len = elems.length; _i < _len; _i++) {
      elem = elems[_i];
      elem.style.display = "list-item";
    }
   
};
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
jQuery
$("#main ul li").hide();
pending…
DOM
var elem, elems, _i, _len;

elems = document.querySelectorAll("#main ul li");

for (_i = 0, _len = elems.length; _i < _len; _i++) {
  elem = elems[_i];
  elem.style.display = "none";
}
 
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