akitajs vs jquery, element caching

Benchmark created by Espen Kåsa Notodden on


Description

Personal possibly unfair test comparing my own library to jquery, added in the jquery with selector engine use just for fun and comparison.

Preparation HTML

<div id="mydiv"></div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script><script>Array.prototype.aaid=function(){}; var akita=function(h,d,e){var b={meta:{version:0.1},core:{},core:{type:{isArray:function(a){return Array.isArray?Array.isArray(a):a.aaid?!0:!1},nodelistToArray:function(a){for(var b=[],c=0,c=0;c<a.length;c++)b.push(a[c]);return b},isNumber:function(a){return typeof a==="number"||a instanceof Number},isString:function(a){return typeof a==="string"||a instanceof String},isBoolean:function(a){return typeof a==="boolean"},isRegex:function(a){return a instanceof RegExp}}}};b.dom={selected:"",html:function(a){var a= a||null,f=[],c=b.dom.selected,d=b.core.type.isArray;if(a){if(d(c))for(i=0;i<c.length;i++)c[i].innerHTML=a;else c.innerHTML=a;return this}else if(d(c)){for(i=0;i<c.length;i++)f.push(c[i].innerHTML);return f}else return c.innerHTML},setAttribute:function(a,d){var c=b.dom.selected,e=b.core.type.isArray,g=0;if(e(c))for(g=0;g<c.length;g++)c[g].setAttribute(a,d);else c.setAttribute(a,d);return this},query:function(a,f){if(!b.core.type.isString(a))return!1;var c=f||!0;if(d.querySelectorAll&&c)a=d.querySelectorAll(a), a.length==e?b.dom.selected=a:b.dom.selected=b.core.type.nodelistToArray(a);else if(d.querySelector&&!c)b.dom.selected=d.querySelector(a);else return!1;return this},use:function(a){if(a==b.dom.ws())return this;a.length==e&&!b.core.type.isArray(a)?b.dom.selected=a:b.dom.selected=b.core.type.nodelistToArray(a);return this},getById:function(a){b.dom.use(d.getElementById(a));return this},getByTag:function(a){b.dom.use(d.getElementsByTagName(a));return this},ws:function(){return b.dom.selected}};return{html:b.dom.html, attr:b.dom.setAttribute,use:b.dom.use,isArray:b.core.type.isArray,query:b.dom.query,ws:b.dom.ws,getById:b.dom.getById,getByTag:b.dom.getByTag}}(this,document,void 0);</script>
<script>
  acached = document.getElementById("mydiv");
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
akitajs with caching
akita.use(acached);
ready
jquery without caching
$("#mydiv");
ready
jquery with caching
$(acached);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by Espen Kåsa Notodden on