Handlebars compile vs precompile (v6)

Revision 6 of this benchmark created on


Preparation HTML

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0/handlebars.min.js"></script>
<script id="example" type="text/x-handlebars-template"><div> {{ exampleText }} </div></script>
<script>(function(){var e=Handlebars.template,t=Handlebars.templates=Handlebars.templates||{};t["example"]=e(function(e,t,n,r,i){this.compilerInfo=[4,">= 1.0.0"];n=this.merge(n,e.helpers);i=i||{};var s="",o,u="function",a=this.escapeExpression;s+="<div> ";if(o=n.exampleText){o=o.call(t,{hash:{},data:i})}else{o=t.exampleText;o=typeof o===u?o.apply(t):o}s+=a(o)+" </div>";return s})})()</script>
<script>
$(document).ready(function() {
var context = { exampleText: 'test' };
window.compile = function(){
        var theTemplate = Handlebars.compile($("#example").html());
        return theTemplate(context);
}
window.precomplied = function(){
        var theTemplate = Handlebars.templates['example']
        return theTemplate(context);
}

});
</script>
</head>
<body>


</body>
</html>

Test runner

Ready to run.

Testing in
TestOps/sec
Normal Compilation
window.compile();
ready
Precomp
window.precomplied();
ready

Revisions

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