Hogan.js vs. Mustache (v4)

Revision 4 of this benchmark created on


Description

Updated the test to not add to innerHTML nor depend on jQuery as it might infringe on the real performance.

Preparation HTML

<script src="//goo.gl/OCK7V"></script>
<script src="https://raw.github.com/janl/mustache.js/master/mustache.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" }
      ],
    
      "citation": function() {
        return {
          authorName: "Dan Gilbert",
          year: "2011"
        };
      }
    };
    var template = "{{#messages}}{{greeting}}, {{subject}}{{/messages}}{{#citation}}{{authorName}}, {{year}}{{/citation}}";
    var compiled = Hogan.compile(template);

Test runner

Ready to run.

Testing in
TestOps/sec
Rendering with Mustache
var html = Mustache.to_html(template, context);


var sys = require('sys');
var mustache = require('mustache');

var view = {
  title: "Joe",
  calc: function() {
    return 2 + 4;
  }
};

var template = "{{title}} spends {{calc}}";

var html = mustache.to_html(template, view);

sys.puts(html); 
ready
Rendering with Hogan.js (uncompiled)
var compiledTemplate = Hogan.compile(template);
var html = compiledTemplate.render(context);
 
ready
Rendering with Hogan.js (compiled)
var html = compiled.render(context);
ready

Revisions

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