Y.Template.Micro vs. others (v4)

Revision 4 of this benchmark created by Ryan Grove on


Preparation HTML

<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<script src="http://yui.yahooapis.com/3.6.0/build/yui/yui-min.js"></script>
<script>
var Y = YUI().use('escape', 'handlebars', function (Y) {

Y.Get.script('https://raw.github.com/rgrove/yui3/template/src/template/js/template-micro.js');

});
</script>

Setup

var yuiTemplate = "<ul class='<%=classNames.list%>'><% for (var i=0, len=items.length; i < len; i++) { %><li class='item'><%=items[i]%></li><% } %></ul>";
    
    var yuiTemplateNoWith = "<ul class='<%=data.classNames.list%>'><% for (var i=0, len=data.items.length; i < len; i++) { %><li class='item'><%=data.items[i]%></li><% } %></ul>";
    
    var handlebarsTemplate = "<ul class='{{classNames.list}}'>{{#items}}<li class='item'>{{.}}</li>{{/items}}</ul>";
    
    var underscoreTemplate = "<ul class='<%-classNames.list%>'><% for (var i=0, len=items.length; i < len; i++) { %><li class='item'><%-items[i]%></li><% } %></ul>";
    
    var underscoreTemplateNoWith = "<ul class='<%-data.classNames.list%>'><% for (var i=0, len=data.items.length; i < len; i++) { %><li class='item'><%-data.items[i]%></li><% } %></ul>";
    
    var compiledYUI = Y.Template.Micro.compile(yuiTemplate);
    var compiledYUINoWith = Y.Template.Micro.compile(yuiTemplateNoWith, {variable: 'data'});
    var compiledHandlebars = Y.Handlebars.compile(handlebarsTemplate);
    var compiledUnderscore = _.template(underscoreTemplate);
    var compiledUnderscoreNoWith = _.template(underscoreTemplateNoWith, null, {variable: 'data'});
    
    var data = {
        classNames: {list: 'test-list'},
        items: ['foo', 'bar', "'baz'", '<quux>', 'cats & dogs', 'monkeys & bananas']
    };

Test runner

Ready to run.

Testing in
TestOps/sec
[precompiled] Underscore
window.result = compiledUnderscore(data);
ready
[precompiled] Y.Template.Micro
window.result = compiledYUI(data);
ready
[precompiled] Y.Handlebars
window.result = compiledHandlebars(data);
ready
[precompiled, no with] Underscore
window.result = compiledUnderscoreNoWith(data);
ready
[precompiled, no with] Y.Template.Micro
window.result = compiledYUINoWith(data)
ready
[compile + render] Underscore
window.result = _.template(underscoreTemplate, data);
ready
[compile + render] Y.Template.Micro
window.result = Y.Template.Micro.render(yuiTemplate, data);
ready
[compile + render] Y.Handlebars
window.result = Y.Handlebars.render(handlebarsTemplate, data);
ready

Revisions

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

  • Revision 4: published by Ryan Grove on