Mustache JS engine rumble: Mustache.js vs Handlebars.js vs Hogan.js vs templayed.js (v3)

Revision 3 of this benchmark created by Paul Engel on


Description

Compared Mustache.js, Handlebars.js, Hogan.js and templayed.js.

Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="https://raw.github.com/janl/mustache.js/master/mustache.js"></script>
<script src="http://cloud.github.com/downloads/wycats/handlebars.js/handlebars-1.0.0.beta.6.js"></script>
<script src="https://raw.github.com/twitter/hogan.js/master/web/builds/2.0.0/hogan-2.0.0.min.js"></script>
<script src="https://raw.github.com/archan937/templayed.js/master/src/templayed.js"></script>

Setup

var tests = [
      {
        template: "<p>My name is {{name}}!</p>",
        variables: {name: "Paul Engel"}
      },
      {
        template: "<p>My name is {{name}}!{{!name}}</p>",
        variables: {name: "Paul Engel"}
      },
      {
        template: "<p>{{html}} {{&html}}</p>",
        variables: {html: "<strong>Paul Engel</strong>"}
      },
      {
        template: "<p>{{html}} {{{html}}}</p>",
        variables: {html: "<strong>Paul Engel</strong>"}
      },
      {
        template: "<p>This is shown!{{#show}} Psst, this is never shown{{/show}}</p>",
        variables: {}
      },
      {
        template: "<p>This is shown!{{#show}} Psst, this is never shown{{/show}}</p>",
        variables: {show: false}
      },
      {
        template: "<p>This is shown!{{#shown}} And, this is also shown{{/shown}}</p>",
        variables: {shown: true}
      },
      {
        template: "<p>My name is {{person.first_name}} {{person.last_name}}!</p>",
        variables: {person: {first_name: "Paul", last_name: "Engel"}}
      },
      {
        template: "{{name}}<ul>{{#names}}<li>{{name}}</li>{{/names}}</ul>{{^names}}Sorry, no people to list!{{/names}}",
        variables: {names: []}
      },
      {
        template: "<p>{{name}}</p><ul>{{#names}}<li>{{name}}</li>{{/names}}</ul>{{^names}}Sorry, no people to list!{{/names}}<p>{{name}}</p>",
        variables: {name: "Chunk Norris", names: [{name: "Paul"}, {name: "Engel"}]}
      },
      {
        template: "<ul>{{#names}}<li>{{.}}{{foo}}</li>{{/names}}</ul>",
        variables: {names: ["Paul", "Engel"]}
      },
      {
        template: "<ul>{{#names}}<li>{{fullName}}</li>{{/names}}</ul>",
        variables: {
          names: [{firstName: "Paul", lastName: "Engel"}, {firstName: "Chunk", lastName: "Norris"}],
          fullName: function() {
            return this.lastName + ", " + this.firstName;
          }
        }
      }
    ];
    var compiled = {
      "Handlebars.js": [],
      "Hogan.js": [],
      "templayed.js": []
    };
    for (var i = 0, l = tests.length; i < l; i++) {
      var template = tests[i].template;
      compiled["Handlebars.js"].push(Handlebars.compile(template));
      compiled["Hogan.js"     ].push(Hogan.compile(template));
      compiled["templayed.js" ].push(templayed(template));
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Mustache.js
for (var i = 0, l = tests.length; i < l; i++) {
  var test = tests[i];
  Mustache.to_html(test.template, test.variables);
}
ready
Handlebars.js
for (var i = 0, l = tests.length; i < l; i++) {
  compiled["Handlebars.js"][i](tests[i].variables);
}
ready
Hogan.js
for (var i = 0, l = tests.length; i < l; i++) {
  compiled["Hogan.js"][i].render(tests[i].variables);
}
ready
templayed.js
for (var i = 0, l = tests.length; i < l; i++) {
  compiled["templayed.js"][i](tests[i].variables);
}
ready

Revisions

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