Template Engines Dust JS / Handleebar JS
JavaScript performance comparison
Preparation code
<script src="https://raw.github.com/linkedin/dustjs/master/dist/dust-full-1.1.1.js"></script>
<script src="https://raw.github.com/wycats/handlebars.js/1.0.rc.2/dist/handlebars.js"></script>
<script>
window.sharedVariables = {
header: "Header",
header2: "Header2",
header3: "Header3",
header4: "Header4",
header5: "Header5",
header6: "Header6",
list: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
};
window.handlebarsTemplate = Handlebars.compile("<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}}<li class='item'>{{this}}</li>{{/each}}</ul></div>");
Handlebars.template((function(){var a=Handlebars.template,b=Handlebars.templates=Handlebars.templates||{};b.handlebarsTemplatePrecompiled=a(function(a,b,c,d,e){function p(a,b){var c="",d;return c+="<li class='item'>",d=a,typeof d===l?d=d.call(a,{hash:{}}):d===n&&(d=m.call(a,"this",{hash:{}})),c+=o(d)+"</li>",c}c=c||a.helpers;var f="",g,h,i,j,k=this,l="function",m=c.helperMissing,n=void 0,o=this.escapeExpression;f+="<div><h1 class='header'>",i=c.header,g=i||b.header,typeof g===l?g=g.call(b,{hash:{}}):g===n&&(g=m.call(b,"header",{hash:{}})),f+=o(g)+"</h1><h2 class='header2'>",i=c.header2,g=i||b.header2,typeof g===l?g=g.call(b,{hash:{}}):g===n&&(g=m.call(b,"header2",{hash:{}})),f+=o(g)+"</h2><h3 class='header3'>",i=c.header3,g=i||b.header3,typeof g===l?g=g.call(b,{hash:{}}):g===n&&(g=m.call(b,"header3",{hash:{}})),f+=o(g)+"</h3><h4 class='header4'>",i=c.header4,g=i||b.header4,typeof g===l?g=g.call(b,{hash:{}}):g===n&&(g=m.call(b,"header4",{hash:{}})),f+=o(g)+"</h4><h5 class='header5'>",i=c.header5,g=i||b.header5,typeof g===l?g=g.call(b,{hash:{}}):g===n&&(g=m.call(b,"header5",{hash:{}})),f+=o(g)+"</h5><h6 class='header6'>",i=c.header6,g=i||b.header6,typeof g===l?g=g.call(b,{hash:{}}):g===n&&(g=m.call(b,"header6",{hash:{}})),f+=o(g)+"</h6><ul class='list'>",i=c.list,g=i||b.list,h=c.each,j=k.program(1,p,e),j.hash={},j.fn=j,j.inverse=k.noop,g=h.call(b,g,j);if(g||g===0)f+=g;return f+="</ul></div>\n",f})})());
window.dustTemplatePrecompiledCached = (function(){dust.register("dustTemplatePrecompiledCached",body_0);function body_0(chk,ctx){return chk.write("<div><h1 class='header'>").reference(ctx.get("header"),ctx,"h").write("</h1><h2 class='header2'>").reference(ctx.get("header2"),ctx,"h").write("</h2><h3 class='header3'>").reference(ctx.get("header3"),ctx,"h").write("</h3><h4 class='header4'>").reference(ctx.get("header4"),ctx,"h").write("</h4><h5 class='header5'>").reference(ctx.get("header5"),ctx,"h").write("</h5><h6 class='header6'>").reference(ctx.get("header6"),ctx,"h").write("</h6><ul class='list'>").section(ctx.get("list"),ctx,{"block":body_1},null).write("</ul></div>");}function body_1(chk,ctx){return chk.write("<li class='item'>").reference(ctx.getPath(true,[]),ctx,"h").write("</li>");}return body_0;})();
dust.loadSource(dustTemplatePrecompiledCached, "dustTemplatePrecompiledCached");
window.dustTemplate = function(content) {
dust.render("dustTemplatePrecompiledCached", content, function() {});
};
</script>
<script>
Benchmark.prototype.teardown = function() {
console.log(Handlebars);
};
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
pass |
|
pending… |
handlebar.js |
|
pending… |
handlebar.js (precompiled) |
|
pending… |
dust.js |
|
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 1: published by Tobias Otte
- Revision 2: published
- Revision 3: published
- Revision 4: published
- Revision 5: published
0 comments