Sencha Touch 2 template vs manual

JavaScript performance comparison

Revision 5 of this test case created

Info

Testing the template apply vs manual loop.

Preparation code

<script src="//extjs.cachefly.net/touch/sencha-touch-2.1.0/sencha-touch-all.js">
</script>
<script>
Benchmark.prototype.setup = function() {
    var data = [];
    for (var i = 0; i < 100; i++) {
      data.push({
        id: 'id-' + i,
        title: 'Best title ever',
        content: 'This is the content text',
        img: {
          url: 'http://www.img.com/img.png',
          width: 50,
          height: 50
        }
      });
    }
   
    var tpl = ['<ul>', '<tpl for=".">', '<li id="{id}">', '<h1 class="title">{title}</h1>', '<div class="image" style="background-image: url({img.url}); background-size: {img.height}px {img.width}px;"></div>', '<div class="text">{content}</div>', '</li>', '</tpl>', '</ul>'];
   
    var xtpl = Ext.create('Ext.XTemplate', tpl, {
      compiled: true
    });
   
    function createUL() {
      var ul = document.createElement('ul');
      for (var i = 0; i < data.length; i++) {
        var li = document.createElement('li');
        li.id = data[i].id;
        var h1 = document.createElement('h1');
        h1.classname = 'title';
        h1.appendChild(document.createTextNode(data[i].title));
        var imageDiv = document.createElement('div');
        imageDiv.classname = 'image';
        imageDiv.style = 'background-image: url(' + data[i].img.url + '); background-size: ' + data[i].img.height + 'px ' + data[i].img.width + 'px;';
        var textDiv = document.createElement('div');
        textDiv.classname = 'text';
        textDiv.appendChild(document.createTextNode(data[i].content));
        li.appendChild(h1);
        li.appendChild(imageDiv);
        li.appendChild(textDiv);
        ul.appendChild(li);
      }
      return ul;
    }
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Sencha Touch 2
var res = xtpl.apply(data);
pending…
Manual
var res = createUL();
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