doT vs handlebars

JavaScript performance comparison

Revision 2 of this test case created by tomByrer

Info

v2: new handlebars, used lo-dash, unsure of doT version.

Preparation code

<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.underscore.min.js"></script>
<script type="text/javascript" src="//olado.github.io/doT//doT.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.3.0/handlebars.min.js"></script>
<script>
Benchmark.prototype.setup = function() {
    var dotTemplate = "<h1>Just static text</h1>" +
                   "<p>Here is a simple {{=it.f1}} </p>" +
                   "<div>test {{=it.f2}}" +
                   "<div>{{=it.f3}}</div>" +
                   "<div>{{=it.f4}}</div>" +
                   "</div>";
   
    var hbsTemplate = "<h1>Just static text</h1>" +
                   "<p>Here is a simple {{f1}} </p>" +
                   "<div>test {{f2}}" +
                   "<div>{{f3}}</div>" +
                   "<div>{{f4}}</div>" +
                   "</div>";
   
    var compiledDotTemplate =  doT.template(dotTemplate);
    var compiledHbsTemplate = Handlebars.compile(hbsTemplate);
   
   
    var numberOfInputs = 10000;
    var context = _.map(_.range(numberOfInputs), function (i) {
        return {
            f1: "test" + i,
            f2: "performance" + i,
            f3: "keep" + i,
            f4: "going" + i
        }
    });
};
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
doT test
_.each(context, function (ctx) {
    compiledDotTemplate(ctx);
});
 
pending…
handlebars test
_.each(context, function (ctx) {
    compiledHbsTemplate(ctx);
});
pending…

Compare results of other browsers

Revisions

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:

0 comments

Add a comment