Zepto vs. jQ vs. jQmobi vs. raw

JavaScript performance comparison

Revision 106 of this test case created by

Preparation code

<script src="http://f.cl.ly/items/0t3w1Z2R2L2s0J2D2Q2q/zepto.min.js">
</script>
<script src="http://f.cl.ly/items/2e2P0m3d1Q2U3w01230Y/jq.mobi.min.js">
</script>
<script src="http://f.cl.ly/items/3J2O1D3d0I3a0P2e2V1c/jquery-1.7.2.min.js">
</script>
<script src="http://xuijs.com/downloads/xui-2.3.2.min.js">
</script>
<script src="http://jsrun.it/damele0n/tuMO/js">
</script>
<script src="http://jsrun.it/damele0n/tQkX/js"></script>
<script>
(function(e,t){"use strict";function r(e){return{}.toString.call(e).match(/\s(\w+)/)[1].toLowerCase()}function i(e){return n.slice.call(e)}function s(e,t){return function(){return e.apply(t||arguments[0],n.slice.call(arguments))}}function o(e){return n.concat.apply([],e)}function u(e){return e.filter(function(t,n){return e.indexOf(t)==n})}function a(e){return e.filter(function(e){return e})}function f(t){var n=e.createElement("div");return n.innerHTML=t,n.childNodes}function l(e){this.el=this._init(e);this.length=this.el.length}function c(e){return new l(e)}var n=Array.prototype;l.prototype={_init:function(t){if(t instanceof l){return t.el}if(r(t)=="array"){return t}if(/html/.test(r(t))){return n.concat.call(t)}if(/^</.test(t)){return i(f(t))}return i(e.querySelectorAll(t))},_new:function(e){this.firstCollect=this.firstCollect||this.el;this.prevCollect=this.el;this.el=a(u(o(e))).reverse();return this},_with:function(e){var t=[];this.each(function(){t.push(e.call(this,this))});return this._new(t)},_targets:function(t,n){var r=e.createDocumentFragment();this.each(function(){r.appendChild(this)});c(t).each(function(){n.call(this,r)});return this},_matches:function(e){var t;if(!e)return this;return this._with(function(n){if(e instanceof l){return e.el.filter(function(e){return e==n})}t=i(this.parentNode.querySelectorAll(e));return~t.indexOf(this)&&this})},_loop:function(e,t){e=e.split(" ");return this._with(function(){var n=[],r,i,s=e.length,o;for(r=0,i=0;r<s;r++){o=this[e[r]];while(o){if(o.nodeType==1)n.unshift(o);if(t&&i==t)break;o=o[e[r]];i++}}return n})},each:function(e){return this.el.some(s(e)),this},slice:function(e,t){return this._new(this.el.slice(e,t))},map:function(e){return this._new(this.el.map(s(e)))},end:function(){return this._new(this.firstCollect)},filter:function(e){if(r(e)=="function"){return this._new(this.el.filter(s(e)))}return this._matches(e)},not:function(e){var t=c(this)._matches(e).el;return this._with(function(){return!~t.indexOf(this)&&this})},is:function(e){return!!this._matches(e).length},find:function(e){return this._with(function(){return i(this.querySelectorAll(e))})},children:function(e){return this._with(function(){return i(this.children)})._matches(e)},parents:function(e){return this._loop("parentNode")._matches(e)},parent:function(e){return this._with(function(){return this.parentNode})._matches(e)},siblings:function(e){return this._loop("previousSibling nextSibling")._matches(e)},prevAll:function(e){return this._loop("previousSibling")._matches(e)},nextAll:function(e){return this._loop("nextSibling")._matches(e)},clone:function(){return this.map(function(){return this.cloneNode(true)})},appendTo:function(e){return this._targets(e,function(e){this.appendChild(e)})}};t._=c})(document,window)
</script>
<div id="asdf">
<p><em></em></p>
</div>
      
<script>
Benchmark.prototype.setup = function() {
  function el(string) {
    if (string.indexOf('#') === 0) {
      return document.getElementById(string.substr(1, string.length));
    }
  }
  
  //to be fair, I'll wrap getElementById in a function and return the object
  
  byId = document.getElementById.bind(document);
  
  var boolean = true;

};
</script>

Preparation code output

<script src="http://f.cl.ly/items/2e2P0m3d1Q2U3w01230Y/jq.mobi.min.js"> </script> <script src="http://f.cl.ly/items/3J2O1D3d0I3a0P2e2V1c/jquery-1.7.2.min.js"> </script> <script src="http://xuijs.com/downloads/xui-2.3.2.min.js"> </script> <script src="http://jsrun.it/damele0n/tuMO/js"> </script> <script src="http://jsrun.it/damele0n/tQkX/js"></script> <script> (function(e,t){"use strict";function r(e){return{}.toString.call(e).match(/\s(\w+)/)[1].toLowerCase()}function i(e){return n.slice.call(e)}function s(e,t){return function(){return e.apply(t||arguments[0],n.slice.call(arguments))}}function o(e){return n.concat.apply([],e)}function u(e){return e.filter(function(t,n){return e.indexOf(t)==n})}function a(e){return e.filter(function(e){return e})}function f(t){var n=e.createElement("div");return n.innerHTML=t,n.childNodes}function l(e){this.el=this._init(e);this.length=this.el.length}function c(e){return new l(e)}var n=Array.prototype;l.prototype={_init:function(t){if(t instanceof l){return t.el}if(r(t)=="array"){return t}if(/html/.test(r(t))){return n.concat.call(t)}if(/^</.test(t)){return i(f(t))}return i(e.querySelectorAll(t))},_new:function(e){this.firstCollect=this.firstCollect||this.el;this.prevCollect=this.el;this.el=a(u(o(e))).reverse();return this},_with:function(e){var t=[];this.each(function(){t.push(e.call(this,this))});return this._new(t)},_targets:function(t,n){var r=e.createDocumentFragment();this.each(function(){r.appendChild(this)});c(t).each(function(){n.call(this,r)});return this},_matches:function(e){var t;if(!e)return this;return this._with(function(n){if(e instanceof l){return e.el.filter(function(e){return e==n})}t=i(this.parentNode.querySelectorAll(e));return~t.indexOf(this)&&this})},_loop:function(e,t){e=e.split(" ");return this._with(function(){var n=[],r,i,s=e.length,o;for(r=0,i=0;r<s;r++){o=this[e[r]];while(o){if(o.nodeType==1)n.unshift(o);if(t&&i==t)break;o=o[e[r]];i++}}return n})},each:function(e){return this.el.some(s(e)),this},slice:function(e,t){return this._new(this.el.slice(e,t))},map:function(e){return this._new(this.el.map(s(e)))},end:function(){return this._new(this.firstCollect)},filter:function(e){if(r(e)=="function"){return this._new(this.el.filter(s(e)))}return this._matches(e)},not:function(e){var t=c(this)._matches(e).el;return this._with(function(){return!~t.indexOf(this)&&this})},is:function(e){return!!this._matches(e).length},find:function(e){return this._with(function(){return i(this.querySelectorAll(e))})},children:function(e){return this._with(function(){return i(this.children)})._matches(e)},parents:function(e){return this._loop("parentNode")._matches(e)},parent:function(e){return this._with(function(){return this.parentNode})._matches(e)},siblings:function(e){return this._loop("previousSibling nextSibling")._matches(e)},prevAll:function(e){return this._loop("previousSibling")._matches(e)},nextAll:function(e){return this._loop("nextSibling")._matches(e)},clone:function(){return this.map(function(){return this.cloneNode(true)})},appendTo:function(e){return this._targets(e,function(e){this.appendChild(e)})}};t._=c})(document,window) </script> <div id="asdf"> <p><em></em></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
jQuery
jQuery('#asdf').children().find().parents('body')
pending…
Zepto
Zepto('#asdf').children().find().parents('body')
pending…
jQMobi
pending…
Raw/baseline
pending…
Wrapped Raw
pending…
Straight getElementById
pending…
XUI
pending…
querySelector
pending…
Riddle.js
pending…
kQuery
pending…
joy
_('#asdf').children().find().parents('body')
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