Hogan.js vs. Mustache

Benchmark created by Dan on


Preparation HTML

<div id='content'></div>

<script src="http://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="https://raw.github.com/twitter/hogan.js/master/lib/hogan.js"></script>

Setup

var context = {
      messages: [
        { greeting: "Hello", subject: "World" },
        { greeting: "What's up", subject: "Dan" },
        { greeting: "How's it going", subject: "Ben?" },
        { greeting: "Hello", subject: "World" },
        { greeting: "What's up", subject: "Dan" },
        { greeting: "How's it going", subject: "Ben?" },
        { greeting: "Hello", subject: "World" },
        { greeting: "What's up", subject: "Dan" },
        { greeting: "How's it going", subject: "Ben?" },
        { greeting: "Hello", subject: "World" }
      ],
    
      "shouldRenderApple?" : function() {
        return true;
      },
    
      "citation": function() {
        return {
          authorName: "Dan Gilbert",
          year: "2011"
        };
      }
    };

Test runner

Ready to run.

Testing in
TestOps/sec
Rendering with Mustache
var template = "{{# messages }}<li>{{ greeting }}, {{ subject }} {{# shouldRenderApple? }} APPLE {{/ shouldRenderApple? }}</li>{{/ messages }}{{# citation }}{{ authorName }}, {{ year }}{{/ citation }}";
$("#content").html(Mustache.to_html(template, context));
 
ready
Rendering with Hogan.js (uncompiled)
var template = "{{# messages }}<li>{{ greeting }}, {{ subject }} {{# shouldRenderApple? }} APPLE {{/ shouldRenderApple? }}</li>{{/ messages }}{{# citation }}{{ authorName }}, {{ year }}{{/ citation }}";
var compiledTemplate = Hogan.compile(template);
$("#content").html(compiledTemplate.render(context));
 
ready

Revisions

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