native vs zepto vs jquery - selectors

JavaScript performance comparison

Revision 49 of this test case created by Mauro Junior

Preparation code

<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<script src="http://zeptojs.com/zepto.min.js"></script>

<div id="rsvp" class="view" data-view-title="RSVPs">
    <div class="content"></div>
</div>
<div id="chapter_004" class="view" data-view-title="Splendid Corgi Consortium">
    <div class="content"></div>
</div>
<script>
Benchmark.prototype.setup = function() {
    var getById = function(id) {
        return document.getElementById(id)
      },
      getByClass = function(cls) {
        return document.getElementsByClassName(cls)
      },
      querySelectorAll = function(query) {
        return document.querySelectorAll(query)
      },
      querySelector = function(query) {
        return document.querySelector(query)
      };
};
</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
Zepto ID
Zepto('#chapter_004')
pending…
jQuery ID
jQuery('#chapter_004')
pending…
getElementById
document.getElementById('chapter_004')
pending…
Zepto ClassName
Zepto('.view')
pending…
jQuery ClassName
jQuery('.view')
pending…
getElementsByClassName
document.getElementsByClassName('view')
pending…
querySelectorAll
document.querySelectorAll('.view')
pending…
querySelector
document.querySelector('#chapter_004')
pending…
getElementById cached
getById('chapter_004');
pending…
getElementsByClassName cached
getByClass('view');
pending…
querySelectorAll cached
querySelectorAll('.view');
pending…
querySelector cached
querySelector('#chapter_004')
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