doT.js vs. Handlebars precompile (v6)

Revision 6 of this benchmark created on


Description

A test to show benchmark for popular JS templaters.

Preparation HTML

<script type="text/javascript" src="https://rawgithub.com/olado/doT/master/doT.js">
</script>

<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.1.0/handlebars.min.js"></script>

<script type="text/javascript">
window.sharedVariables = [{
  first_name: 'Alex',
  last_name: null,
  age: 24,
  gender: 'male'
},
{
  first_name: 'Jane',
  last_name: 'Painkiller',
  age: 26,
  gender: 'female'
}];

window.dotTemplate = '{{~it:x}}<li class="people {{=x.gender}}"><span class="name">{{=x.first_name}}{{? x.last_name}} {{=x.last_name}}{{?}}</span><span class="age">{{=x.age}}</span></li>{{~}}';

window.dotCompiled = doT.template(dotTemplate);

window.handlebarsTemplate = '{{#.}}<li class="people {{gender}}"><span class="name">{{first_name}}{{#if last_name}} {{last_name}}{{/if}}</span><span class="age">{{age}}</span></li>{{/.}}';

window.handlebarsCompiled = Handlebars.compile(handlebarsTemplate);
</script>

Setup

var tplStr = document.getElementById('tpl').innerHTML;
    
    var tplVash = vash.compile(tplStr, { modelName: 'it', debug: false });
    
    var model = { 
        Do: 'DO', 
        realize: function(){ return 'REALIZE' }, 
        everyone: function(p){ return { go: p }; }, 
        floating: 'FLOATING' 
    }

Test runner

Ready to run.

Testing in
TestOps/sec
doT.js precompiled
dotCompiled(sharedVariables);
ready
Handlebars.js precompiled
handlebarsCompiled(sharedVariables);
ready

Revisions

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