JavaScript template engine compare
JavaScript performance comparison
Info
No precompile. @see precompile at http://jsperf.com/javascript-template-engine-compare/3
Preparation code
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="https://raw.github.com/documentcloud/underscore/master/underscore.js"></script>
<script src="https://raw.github.com/janl/mustache.js/master/mustache.js"></script>
<script src="http://borismoore.github.com/jsrender/jsrender.js"></script>
<script src="https://github.com/olado/doT/raw/master/doT.js"></script>
<script src="https://raw.github.com/tenbits/MaskJS/master/lib/mask.js"></script>
<!--External Template Definitions-->
<script>
window.sharedVariables = {
header: "Header",
header2: "Header2",
header3: "Header3",
header4: "Header4",
header5: "Header5",
header6: "Header6",
list: ['1000000000', '2', '3', '4', '5', '6', '7', '8', '9', '10']
};
window.maskTemplateRaw = "div { \
h1.header > '#{header}'\
h2.header2 > '#{header2}'\
h3.header3 > '#{header3}'\
h4.header4 > '#{header4}'\
h5.header5 > '#{header5}'\
h6.header6 > '#{header6}'\
ul.list > list value='list' > li.item > '#{.}'\
}";
window.maskDom = mask.compile(maskTemplateRaw)
//JsRender compiled template (no encoding)
window.jsRenderTemplateRaw = "<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'>{{for list}}<li class='item'>{{:#data}}</li>{{/for}}</ul></div>";
window.jsRenderTemplate = $.templates(jsRenderTemplateRaw);
window.mustacheTemplateRaw = "<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'>{{#list}}<li class='item'>{{{.}}}</li>{{/list}}</ul></div>";
window.underscoreTemplateRaw = "<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'><% for (var i = 0, l = list.length; i < l; i++) { %><li class='item'><%= list[i] %></li><% } %></ul></div>";
window.underscoreTemplate = _.template(underscoreTemplateRaw);
window.underscoreTemplateNoWithRaw = "<div><h1 class='header'><%= data.header %></h1><h2 class='header2'><%= data.header2 %></h2><h3 class='header3'><%= data.header3 %></h3><h4 class='header4'><%= data.header4 %></h4><h5 class='header5'><%= data.header5 %></h5><h6 class='header6'><%= data.header6 %></h6><ul class='list'><% for (var i = 0, l = data.list.length; i < l; i++) { %><li class='item'><%= data.list[i] %></li><% } %></ul></div>";
window.underscoreTemplateNoWith = _.template(underscoreTemplateNoWithRaw, null, {variable: 'data'});
window.doTtemplateRaw = "<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'>{{ for (var i=0,l=it.list.length;i<l;i++) { }}<li class='item'>{{=it.list[i]}}</li>{{ } }}</ul></div>";
window.doTtemplate = doT.template(doTtemplateRaw);
</script>
<div id="template" style=""></div>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
doT.js |
|
pending… |
Underscore.js Template |
|
pending… |
Underscore.js Template (No "with") |
|
pending… |
JsRender |
|
pending… |
Mustache.js Template |
|
pending… |
MaskJs renderDom |
|
pending… |
MaskJs renderHtml |
|
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:
- Revision 2: published by tenbits
- Revision 3: published by tenbits
- Revision 4: published by Lafncow
- Revision 5: published by Zibx
- Revision 6: published by Zibx
- Revision 7: published by Zibx
- Revision 8: published by tenbits
- Revision 9: published by tenbits
- Revision 10: published by tenbits
- Revision 12: published by interfaced
- Revision 14: published
- Revision 15: published
- Revision 16: published by tenbits
- Revision 17: published by Vladimir
- Revision 18: published by Heitor Salazar Baldelli
- Revision 19: published
- Revision 20: published by MobileSam
- Revision 23: published by Compvir
- Revision 24: published by yurkom
- Revision 25: published
- Revision 26: published by tenbits
- Revision 27: published by tenbits
- Revision 28: published
- Revision 29: published
- Revision 36: published by dinedal
- Revision 37: published and last updated
- Revision 39: published
- Revision 40: published
- Revision 41: published
- Revision 42: published
- Revision 43: published
- Revision 44: published
- Revision 45: published
- Revision 46: published
- Revision 47: published
- Revision 48: published
- Revision 49: published
- Revision 50: published
- Revision 51: published
- Revision 52: published
- Revision 53: published
- Revision 54: published
- Revision 55: published
- Revision 56: published
- Revision 57: published
- Revision 58: published
- Revision 59: published
- Revision 61: published by Stefan
- Revision 62: published
- Revision 63: published by iKBAHT
- Revision 64: published
- Revision 65: published by tenbits
0 comments