Sencha Touch 2 template vs manual

JavaScript performance comparison

Revision 6 of this test case created


Testing the template apply vs manual loop. Both return the text string containing data to be inserted.

Preparation code

<script src="">
Benchmark.prototype.setup = function() {
    function getData(){
    d = [];
    for (var i = 0; i < 0; i++) {
        id: 'id-' + i,
        title: 'Best title ever',
        content: 'This is the content text',
        img: {
          url: '',
          width: 50,
          height: 50
    return d;
    var tmpl_1 = ['<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', tmpl_1, {
      compiled: true
    var tmpl_2= ['<li id="','1','"><h1 class="title">','3','</h1><div class="image" style="background-image: url(','5','); background-size: ','7','px ','9','px;"></div><div class="text">','11','</div></li>'];
    function createUL(data) {
      var buffer = [],j = 0;
      buffer[j++] = '<ul>';
      for (var i = 0; i < data.length; i++) {
        tmpl_2[1] = data[i].id;
        tmpl_2[3] = data[i].title;
        tmpl_2[5] = data[i].img.url;
        tmpl_2[7] = data[i].img.height;
        tmpl_2[9] = data[i].img.width;
        tmpl_2[11] = data[i].content;
        buffer[j++] = tmpl_2.join("");
      buffer[j++] = '</ul>';
      return buffer.join("");

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(getData());
var res = createUL(getData());

Compare results of other browsers


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:


Comment form temporarily disabled.

Add a comment