zepto-vs-joy

JavaScript performance comparison

Revision 7 of this test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
var L=console.log.bind(console);(function(e,t){function s(e){this.el=this._init(e)}function o(e){return new s(e)}var n=Array.prototype,r=t.JOY={curry:function(e,t){return function(){return e.apply(t||arguments[0],n.slice.call(arguments))}},flatten:function(e){return n.concat.apply([],e)},uniq:function(e){return e.filter(function(t,n){return e.indexOf(t)==n})}},i={loopAll:function(e,t){var n=[],r=e[t];while(r){if(r.nodeType==1)n.push(r);r=r[t]}return n}};s.prototype={_init:function(t){if(typeof t=="string"){return n.slice.call(e.querySelectorAll(t))}return r.uniq(r.flatten(t))},_new:function(e){return new s(e)},_matches:function(e){if(!e)return this;var t=[];this.each(function(){var r=n.slice.call(this.parentNode.querySelectorAll(e));r.forEach(function(e){if(e==this)t.push(this)}.bind(this))});return this._new(t)},each:function(e){return this.el.some(r.curry(e)),this},query:function(e){var t=/^(>|\+|~)(.*)/.exec(e)||[,null,null];var r=t[1],s=t[2],o=[];this.each(function(){switch(r){case null:case">":o.push(n.slice.call(this.children));break;case"+":o.push(i.loopAll(this,"parentNode"));break;case"~":o.push(i.loopAll(this,"previousSibling"),i.loopAll(this,"nextSibling"));break;default:o.push(n.slice.call(this.querySelectorAll(e)))}});return this._new(o)._matches(s)}};t._=o})(document,window)
</script>

<div id="testdiv1">
  <p><em>Foo</em></p>
  <p><em>Foo</em></p>
</div>
<script>
Benchmark.prototype.setup = function() {
    jQuery.noConflict();
};
</script>

Preparation code output

Foo

Foo

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
jQuery('#testdiv1 p').children()
pending…
joy
_(document.getElementById('#testdiv1 p')).query()
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