underscore vs doT vs kata (v2)

Revision 2 of this benchmark created by Cang on


Preparation HTML

<script src="http://underscorejs.org/underscore-min.js"></script>
<script src="http://olado.github.io/doT/doT.min.js"></script>
<script src="http://rawgithub.com/smcmurray/kata/master/kata.min.js"></script>

<script>
  window.sharedVariables = {
        header: "Some text",
        header2: "More text",
        header3: "Allows \"double quotes\"",
        header4: "& isn't &amp;",
        header5: "<escaped ok='true'>",
        header6: "Bold text",
        list: ['1 <ok>', '2 <ok>', '3 <ok>', '4 <ok>', '5 <ok>', '6 <ok>', '7 <ok>', '8 <ok>', '9 <ok>', '10 <ok>']
    };




window.templateDiv = document.getElementById("template");

window.doTTemplate = doT.template("<div><h1 class='header'>{{=it.header}}</h1><h2 class='header2'>{{=it.header2}}</h2><h3 class='header3'>{{=it.header3}}</h3><h4 class='header4'>{{=it.header4}}</h4><h5 class='header5'>{{=it.header5}}</h5><h6 class='header6'>{{=it.header6}}</h6><ul class='list'>{{~it.list:l}}<li class='item'>{{=l}}</li>{{~}}</ul></div>");

window.underscoreTemplate = _.template("<div><h1 class='header'><%=header%></h1><h2 class='header2'><%=header2%></h2><h3 class='header3'><%=header3%></h3><h4 class='header4'><%=header4%></h4><h5 class='header5'><%=header5%></h5><h6 class='header6'><%=header6%></h6><ul class='list'><% _.each(list, function(name) { %><li class='item'><%= name %></li><% }); %></ul></div>");

window.kataTemplate = kata("{{%(t)<div><h1 class='header'>{{t.header}}</h1><h2 class='header2'>{{t.header2}}</h2><h3 class='header3'>{{t.header3}}</h3><h4 class='header4'>{{t.header4}}</h4><h5 class='header5'>{{t.header5}}</h5><h6 class='header6'>{{t.header6}}</h6><ul class='list'>{{@(t.list)(l)<li class='item'>{{l}}</li>@}}</ul></div>%}}");
</script>

<div id="template" style="display:none"></div>

Test runner

Ready to run.

Testing in
TestOps/sec
Underscore
templateDiv.innerHTML = underscoreTemplate(sharedVariables);
ready
doT
templateDiv.innerHTML = doTTemplate(sharedVariables);
ready
Kata
templateDiv.innerHTML = kataTemplate(sharedVariables);
ready

Revisions

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

  • Revision 1: published by Cang on
  • Revision 2: published by Cang on