jQ.Mobi VS zepto (v79)

Revision 79 of this benchmark created on


Description

This is an edited test from http://jsperf.com/jqm3/26 by @DevinRhode2

I added a raw JS baseline, and another test that uses javascript prototypes to create some jquery-like abstraction, but yield nearly the same performance as raw JS. This makes one consider the Prototype javascript library. In attempting to add the Prototype version, I decided that it's too different, even as a pretty well versed javascript developer.

From: http://api.prototypejs.org/dom/Element/new/, a Prototype test case would look something like this:

var ul = new Element('ul').update("<li>Hello PrototypeJS world, you're strange.");

.update? .text or .innerText are far too commonplace, and .update truly threw me for a second. PrototypeJS is great, but I'd rather see a jQ.Mobi re-write that heavily uses prototypes of native objects. By my investigation on their docs site, prototypes don't seem modified at all. I'm curious about the feasibility of a jQ.Mobi re-write that heavily uses prototypes

Preparation HTML

<script src="//zeptojs.com/zepto.min.js">
</script>
<script src="//cdn.jqmobi.com/jq.mobi.min.js">
</script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div id="container">
</div>

Setup

var d = {};
    d.id = function(el) {
      return document.getElementById(el);
    }
    d.create = function(el) {
      return document.createElement(el);
    }
    
    //Lets add the append method to all html dom nodes:
    HTMLElement.prototype.append = function(el) {
      this.appendChild(el);
    }
    var container = d.id('container');
    var ul, li, i = 0;

Teardown


    container.innerHTML = "";
  

Test runner

Ready to run.

Testing in
TestOps/sec
jQ.Mobi
ul = jq("<ul/>");
for (; i < 100; i += 1) {
  li = jq("<li>hello world jq.Mobi</li>");
  ul.append(li);
}
jq(d.id('container')).append(ul);
ready
jQuery
ul = jQuery("<ul/>");
for (; i < 100; i += 1) {
  li = jQuery("<li>hello world jQuery</li>");
  ul.append(li);
}
jQuery(d.id('container')).append(ul);
ready
Zepto
ul = Zepto("<ul/>");
for (; i < 100; i += 1) {
  li = Zepto("<li>hello world Zepto</li>");
  Zepto(ul).append(li);
}
Zepto(d.id('container')).append(ul);
ready
Raw JS - Building DOM nodes
i, ul = document.createElement("ul");
for (; i < 100; i += 1) {
  li = document.createElement("li");
  li.innerText = 'hello world raw JS';
  ul.appendChild(li);
}
document.getElementById("container").appendChild(ul);
ready
some jQuery style, native performance with prototypes
ul = d.create("ul");
for (; i < 100; i += 1) {
  li = d.create("li");
  li.innerText = 'hello world almost raw JS';
  ul.append(li);
}
jq("#container")[0].append(ul);
ready
jq.mobi
ul = jq("<ul/>");
var html = "";
for (; i < 100; i += 1) {
  html += "<li>hello world jq.Mobi</li>";
}
ul.html(html);
jq(d.id('container')).append(ul);
ready
jq.mobi 2
ul = jq("<ul/>");
var html = [];
for (; i < 100; i += 1) {
  html.push("<li>hello world jq.Mobi</li>");
}
ul.html(html);
jq(d.id('container')).append(ul);
ready

Revisions

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