Underscore templates precompiled performance

JavaScript performance comparison

Test case created by Denis

Info

Benchmarking difference for precompiled underscore templates.

Preparation code

<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js">
</script>
<script>
  Benchmark.prototype.setup = function () {
var template = '<div class="item-<%= id %>"><h1><%= name %></h1><ul class="attributes"><li><%= company.name %></li><li><%= company.address %></li></ul></div>';

    var renderPrecompiled = eval("(" + _.template(template).source + ")");
  };
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Normal
// compile & render template
var output = _.template(template, {
  id: 1,
  name: 'Gianna',
  company: {
    name: 'Westgate',
    address: '19317, ElkGrove, Madison Avenue'
  }
});
pending…
Precompiled
// just render
var output = renderPrecompiled({
  id: 1,
  name: 'Gianna',
  company: {
    name: 'Westgate',
    address: '19317, ElkGrove, Madison Avenue'
  }
});
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:

0 comments

Add a comment