Underscore template caching

JavaScript performance comparison

Test case created by Vladimir Kuznetsov

Preparation code

<script src="http://underscorejs.org/underscore-min.js">
</script>
      
<script>
Benchmark.prototype.setup = function() {
  var text = "<div><% _.each(items, function (item) { %><%= item %> <% }) %></div>";
  var cachedTemplate = _.memoize(_.template);

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
A Texas 2-step
var a = [];
for (var i = 0; i < 10; i++) {
  a.push("" + i);
  _.template(text)({
    items: a
  });
}
pending…
Cached template
var a = [];
for (var i = 0; i < 10; i++) {
  a.push("" + i);
  cachedTemplate(text)({
    items: a
  });
}
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.

0 Comments