Editing Mustache JS engine rumble: Mustache.js vs Handlebars.js vs Hogan.js vs templayed.js This edit will create a new revision. Your details (optional) Name Email (won’t be displayed; might be used for Gravatar) URL Test case details Title * Published (uncheck if you want to fiddle around before making the page public) Description (in case you feel further explanation is needed)(Markdown syntax is allowed) Compared [Mustache.js](https://github.com/janl/mustache.js), [Handlebars.js](http://handlebarsjs.com), [Hogan.js](http://twitter.github.com/hogan.js) and [templayed.js](http://archan937.github.com/templayed.js). Are you a spammer? (just answer the question) Preparation code Preparation code HTML (this will be inserted in the <body> of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries) <script src="//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.rc.1.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> Include JavaScript libraries as follows: <script src="//cdn.ext/library.js"></script> Define setup for all tests (variables, functions, arrays or other objects that will be used in the tests) (runs before each clocked test loop, outside of the timed code region) (e.g. define local test variables, reset global variables, clear canvas, etc.) (see FAQ) 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, {knownHelpersOnly: true, knownHelpers: { 'each': true, 'if': true }})); compiled["Hogan.js" ].push(Hogan.compile(template)); compiled["templayed.js" ].push(templayed(template)); } Define teardown for all tests (runs after each clocked test loop, outside of the timed code region) (see FAQ) Code snippets to compare Test 1 Title Async (check if this is an asynchronous test) Code for (var i = 0, l = tests.length; i < l; i++) { var test = tests[i]; Mustache.to_html(test.template, test.variables); } Test 2 Title Async (check if this is an asynchronous test) Code for (var i = 0, l = tests.length; i < l; i++) { compiled["Handlebars.js"][i](tests[i].variables); } Test 3 Title Async (check if this is an asynchronous test) Code for (var i = 0, l = tests.length; i < l; i++) { compiled["Hogan.js"][i].render(tests[i].variables); } Test 4 Title Async (check if this is an asynchronous test) Code for (var i = 0, l = tests.length; i < l; i++) { compiled["templayed.js"][i](tests[i].variables); }