speedlib vs jquery

JavaScript performance comparison

Test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
(function(){var n=[];this.$=function(a){n.push(a)};$.xtnd=function(a,b){var c=0;return function e(a){for(var b=a.shift(),g=a.length,h=0;h<g;h++){var j=a[h],k;for(k in Object(j))if(j.hasOwnProperty(k)){var l=j[k];"object"==typeof l&&l.prototype===Object.prototype?5>++c?(b[k]={},e([b[k],l])):b[k]=l:b[k]=l}}return b}(Array.prototype.slice.call(arguments))};var p=$,j;j=String.prototype.trim?function(a){return a.trim()}:function(a){for(var b=/\s/;b.test(a.charAt(0));)a=a.substr(1);for(var c=a.length-1;b.test(a.charAt(c));c--)a=a.substr(0,c);return a};p.str={trim:j};p=$;j=Array.prototype.indexOf?function(a,b,c){return Array.prototype.indexOf.call(a,b,c||0)}:function(a,b,c){a.call(function(a){if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var f=0;1<arguments.length&&(f=Number(arguments[1]),f!=f?f=0:0!=f&&(Infinity!=f&&-Infinity!=f)&&(f=(0<f||-1)*Math.floor(Math.abs(f))));if(f>=c)return-1;for(f=0<=f?f:Math.max(c-Math.abs(f),0);f<c;f++)if(f in b&&b[f]===a)return f;return-1})(b,c||0)};p.arr={indexOf:j,ok:function(a){return void 0!==a&&a instanceof Array}};$.func={ok:function(a){return void 0!==a&&"function"==typeof a}};$.indexOf=$.arr.indexOf;$.isFunc=$.func.ok;$.makeNamespace=function(a){"string"==typeof a&&(a=a.split("."));for(var b=$,c=0;c<a.length;c++){var d=a[c];b[d]||(b[d]={});b=b[d]}return b};var h={},q=function(a){this.name=a;this.construct=this.events=this.methods=this.options=this.base=void 0;h[a]=this};q.prototype={makePrototype:function(){var a={__defaultOptions:{},     __constructs:[],__events:[]},b=[],c=[];this.getParents(b);for(var b=b.reverse(),d=0;d<b.length;d++){var e=b[d];c.push(e.Class);$.isFunc(e.construct)&&a.__constructs.push(e.construct);e.options&&$.xtnd(a.__defaultOptions,e.options);e.methods&&$.xtnd(a,e.methods);e.events instanceof Array&&(a.__events=a.__events.concat(e.events))}$.isFunc(this.construct)&&a.__constructs.push(this.construct);this.options&&$.xtnd(a.__defaultOptions,this.options);this.methods&&$.xtnd(a,this.methods);this.events instanceof Array&&a.__events.concat(this.events);0<a.__events.length&&($.xtnd(a,h.Listener.methods),a.__constructs.push(h.Listener.construct));a.instanceOf=function(a){for(var b=!1,d=0;d<c.length;d++)c[d]===a&&(b=!0);return b};return a},getParents:function(a){if(this.base){if(h[this.base.name]){var b=h[this.base.name];a.push(b);return b.base?b.getParents(a):b}if($.isFunc(this.base)&&""!=this.base.name){var b=this.base,c=new q(b.name);c.options=Object(new b);c.methods=b.prototype;c.construct=b.prototype.constructor;c.Class=b;c.protoCopy=$.xtnd({},b.prototype);a.push(c);return c}}else return!1}};$.Class=function(a,b){var c=$,d="_$"+a.toString();if(-1!=a.search(".")){var e=a.split("."),d="_$"+e.join("");a=e.pop();c=$.makeNamespace(e)}e=new q(a);b(e);eval("function "+d+"(opts){$.Class.construct.call(this,e,opts);}");d=c[a]=eval(d);d.prototype=$.xtnd(e.makePrototype());e.protoCopy=$.xtnd({},d.prototype);delete d.prototype.__events;delete d.prototype.__constructs;delete d.prototype.__defaultOptions;return e.Class=d};$.Class.construct=function(a,b){var c=a.protoCopy;$.xtnd(this,c.__defaultOptions,b);for(var d=0;d<c.__constructs.length;d++)c.__constructs[d].call(this);for(d=0;d<c.__events.length;d++)this.addEvent(c.__events[d],this)};this.speed=$;var g=this.document,m=function(){var a=g.readyState;if("interactive"==a||"complete"==a){g.removeEventListener?g.removeEventListener("readystatechange",m):g.detachEvent&&g.detachEvent("onreadystatechange",m);for(var a=n.length,b=0;b<a;b++)(0,n[b])()}};g.addEventListener?g.addEventListener("readystatechange",m):g.attachEvent&&g.attachEvent("onreadystatechange",m)})();

(function(e){var g=document.createDocumentFragment(),k;k=document.textContent?function(a,b){a.textContent=b}:function(a,b){a.innerText=b};var l;l=document.textContent?function(a){return a.textContent}:function(a){for(var b="",c=0,d=a.childNodes.length;c<d;c++)3==a.childNodes[c].nodeType&&(b+=a.childNodes[c].nodeValue);return b};var m;m=document.getElementsByClassName?function(a,b,c){c=c||document;a=c.getElementsByClassName(a);return b?Array.filter(a,function(a){return a.nodeName==b.toUpperCase()}):
        a}:function(a,b,c){b=c?c.getElementsByTagName(b||"*"):document.all;var d=a.split(" ");a=[];c=[];for(var f=0,h=d.length;f<h;f++)a.push(RegExp("(^|\\s)"+d[f]+"(\\s|$)"));d=!1;f=0;for(h=b.length;f<h;f++){for(var e=0,g=a.length;e<g&&!(d=a[e].test(b[f].className),!d);e++);d&&(c.push(b[f]),d=!1)}return c};e.dom=function(a){var b;if("string"==typeof a)b=a.charAt(0),b="#"==b?[document.getElementById(a.substr(1))]:"."==b?m(a.substr(1)):document.getElementsByTagName(a);else if(a instanceof(NodeList||HTMLCollection)||
        a instanceof Array)b=a;else if(a instanceof(Node||Element))b=[a];else return a;a={length:b.length,nodeList:b,qry:a};for(var c=0,d=a.length;c<d;c++)a[c]=b[c];return new e.dom.Set(a)};e.Class("dom.Set",function(a){a.options={qry:void 0};a.methods=e.xtnd({each:function(b){for(var a=0,d=this.length;a<d;a++)b.call(this[a],a,this[a]);return this},txt:function(b){if(b)return this.each(function(){k(this,b)});var a=[];this.each(function(){a.push(l(this))});return a},detach:function(){return this.each(function(){g.appendChild(this)})},
        append:function(b){return this.each(function(a,d){b.each(function(){d.appendChild(this)})})},appendTo:function(b){return this.each(function(a,d){g.appendChild(d);b.each(function(b,a){a.appendChild(d)})})},prepend:function(){},insertBefore:function(b){return this.each(function(a,d){b.each(function(b,a){a.parentNode.insertBefore(d,a)})})},insertAfter:function(a){return this.each(function(c,d){a.each(function(a,b){b.parentNode.insertBefore(d,b.nextSibling)})})},prependTo:function(a){return this.each(function(c,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   d){a.each(function(a,b){b.insertBefore(d,b.childNodes[b.childNodes.length-1])})})},removeAttr:function(){return this.each(function(){})},attr:function(a,c){if("string"==typeof a){if(void 0!==c){this.each(function(){this.getAttribute(a)});return}return this.each(function(){this.setAttribute(a,c)})}if(a instanceof Array){var d={};this.each(function(){var c=this.parentNode,h=e.indexOf(c.childNodes,this);g.appendChild(this);for(var j=0;j<a.length;j++)d[a[j]]=this.getAttribute(a[j]);c.insertBefore(this,
                c.childNodes[h])});return d}return a instanceof Object?this.each(function(){for(var c in a)a.hasOwnProperty(c)&&this.setAttribute(c,a[c])}):this},hide:function(){return this.each(function(){var a=e.dom.wrapOne(this);a.__speedData.dom.beforeHide=a.getStyle(["display"]).display;this.style.display="none"})},show:function(){return this.each(function(){var a=e.dom.wrapOne(this);a.__speedData.dom.beforeHide?this.style=a.__speedData.dom.beforeHide:this.style.display="default"})},next:function(){},prev:function(){},
        parent:function(){},children:function(){},destroy:function(){},clone:function(){},concat:Array.prototype.concat,join:Array.prototype.join,pop:function(){return e.dom(Array.prototype.pop.call(this))},push:Array.prototype.push,reverse:Array.prototype.reverse,shift:Array.prototype.shift,slice:Array.prototype.slice,sort:Array.prototype.sort,splice:Array.prototype.splice,unshift:Array.prototype.unshift});a.events=[];a.construct=function(){}})})(speed);
</script>

<div id='topDiv'></div>
<div id="midDiv"></div>
<div id="botDiv"></div>


        <div id="test1" class="test"></div>
        <div id="test2" class="test"></div>
        <div id="test3" class="test"></div>
        <div id="test4" class="test"></div>
        <div id="test5" class="test"></div>

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
speedLib
                var $$ = speed;
                //var $$topDiv = $$.dom('#topDiv');
                //var $$botDiv = $$.dom('#botDiv');
                var $$allTest = $$.dom('.test');
        //$$topDiv.append($$allTest);
//      $$allTest.insertAfter($$botDiv);
pending…
jquery
        var $ = jQuery;
//      var $topDiv = $('#topDiv');
        //var $botDiv = $('#botDiv');
        var $allTest = $('.test');
        //      $topDiv.append($allTest);
        //      $allTest.insertAfter($botDiv);
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