Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions benchmark/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,18 @@ <h1>shootout</h1>

<div id="content">
<div id="charts"></div>
<p style="clear: both">Targets: <a href="http://akdubya.github.com/dustjs">Dust</a>, <a href="http://github.com/wycats/handlebars.js">Handlebars</a>, <a href="http://mustache.github.com/">Mustache</a>, <a href="http://api.jquery.com/tmpl/">jquery-tmpl</a>. Each benchmark runs once using an adaptive test cycles algorithm similar to the one found in <a href="http://github.com/broofa/jslitmus">jslitmus</a>.</p>
<p style="clear: both">Targets: <a href="http://akdubya.github.com/dustjs">Dust</a>, <a href="http://github.com/wycats/handlebars.js">Handlebars</a>, <a href="http://mustache.github.com/">Mustache</a>, <a href="http://api.jquery.com/tmpl/">jquery-tmpl</a>, <a href="http://underscorejs.org/">Underscore</a>. Each benchmark runs once using an adaptive test cycles algorithm similar to the one found in <a href="http://github.com/broofa/jslitmus">jslitmus</a>.</p>
</div>

<script src="../vendor/jquery.min.js"></script>
<script src="uubench.js"></script>
<script src="../dist/dust-full-0.2.5.min.js"></script>
<script src="../dist/dust-full-0.3.0.min.js"></script>
<script src="http://underscorejs.org/underscore-min.js" ></script>
<script src="suites/dust_suite.js"></script>
<script src="suites/mustache_suite.js"></script>
<script src="suites/handlebars_suite.js"></script>
<script src="suites/jquery_suite.js"></script>
<script src="suites/underscore_suite.js"></script>
<script src="http://github.com/wycats/handlebars.js/raw/766497bb553a926c046c5e5b50ee35529d168ba5/lib/handlebars.js"></script>
<script src="http://github.com/janl/mustache.js/raw/master/mustache.js"></script>
<script src="http://github.com/jquery/jquery-tmpl/raw/master/jquery.tmpl.js"></script>
Expand Down Expand Up @@ -135,6 +137,7 @@ <h1>shootout</h1>
handlebarsBench(suite, type, "handlebars");
mustacheBench(suite, type, "mustache");
jqueryBench(suite, type, "jquery");
underscoreBench(suite, type, "underscore");
suite.run();
}

Expand Down
4 changes: 2 additions & 2 deletions benchmark/suites/handlebars_suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var benches = {
}
}

}
};

exports.handlebarsBench = function(suite, name, id) {
var bench = benches[name],
Expand All @@ -94,7 +94,7 @@ exports.handlebarsBench = function(suite, name, id) {
fn(ctx, {partials: partials});
next();
});
}
};

exports.handlebarsBench.benches = benches;

Expand Down
111 changes: 111 additions & 0 deletions benchmark/suites/underscore_suite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
(function(exports){

var benches = {

string: {
source: "Hello World!",
context: {}
},

replace: {
source: "Hello <%= name %>! You have <%= count %> new messages.",
context: { name: "Mick", count: 30 }
},

array: {
source: "<% _.each(names, function(item) { %> <%= item.name %> <% }); %>",
context: { names: [{name: "Moe"}, {name: "Larry"}, {name: "Curly"}, {name: "Shemp"}] }
},

object: {
source: "<%= person.name %> <%= person.age %>",
context: { person: { name: "Larry", age: 45 } }
},

partial: {
source: "<% _.each(peeps, function(peep) { %> <%= partials.myPartialTemplate(peep) %> <% }); %>",
context: { peeps: [{name: "Moe", count: 15}, {name: "Larry", count: 5}, {name: "Curly", count: 1}] },
partials: { myPartialTemplate: "Hello <%= name %>! You have <%= count %> new messages." }
},

recursion: {
source: "<%= name %> <% _.each(kids, function(kid) { %> <%= partials.recursion({data:kid, partials:partials}) %> <% }); %>",
context: {
name: '1',
kids: [
{
name: '1.1',
kids: [
{name: '1.1.1'}
]
}
]
},
partials: { recursion: "<%= data.name %> <% _.each(data.kids, function(kid) { %> <%= partials.recursion({data:kid, partials:partials}) %> <% }); %>" }
},

filter: {
source: "foo <%= filter(bar) %>",
context: {
filter: function(str) {
return str.toUpperCase();
},
bar: "bar"
}
},

complex: {
source: "<h1><%= header() %></h1>\n" +
"<% if(hasItems) { %>" +
" <% _.each(items, function(item) { %>\n" +
" <ul>\n" +
" <% if(item.current) { %>\n" +
" <li><strong> <%- item.name %> </strong></li>\n" +
" <% } else { %>\n" +
" <li><a href=\" <%- item.url %> \"> <%- item.name %> </a></li>\n" +
" <% } %>\n" +
" </ul>\n" +
" <% }); %>" +
"<% } else { %>\n" +
" <p>The list is empty.</p>\n" +
"<% } %>",
context: {
header: function() {
return "Colors";
},
items: [
{name: "red", current: true, url: "#Red"},
{name: "green", current: false, url: "#Green"},
{name: "blue", current: false, url: "#Blue"}
],
hasItems: function(ctx) {
return ctx.items.length ? true : false;
}
}
}

};

exports.underscoreBench = function(suite, name, id) {
var bench = benches[name],
fn = _.template(bench.source),
ctx = bench.context,
partials = {};

if (bench.partials) {
for (var key in bench.partials) {
partials[key] = _.template(bench.partials[key]);
}
}

ctx.partials = partials;

suite.bench(id || name, function(next) {
fn(ctx);
next();
});
};

exports.underscoreBench.benches = benches;

})(typeof exports !== "undefined" ? exports : window);