underscore-vs-mustache

JavaScript performance comparison

Test case created by Jon Bretman

Preparation code

<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mustache.js/0.8.1/mustache.js"></script>
      
<script>
Benchmark.prototype.setup = function() {
  var mustacheTemplateSrc = '{{#numbers}}{{.}}{{/numbers}}';
  Mustache.parse(mustacheTemplateSrc);
  
  var underscoreTemplateSrc = '<% _.each(context.numbers,function(number){%><% var __$0 = context.number;context.number = number; %><%- number %><% context.number = __$0; %><% }); %>';
  
  var underscoreTemplate = _.template(underscoreTemplateSrc, {variable: 'context'});
  
  var numbers = [];
  for (var i = 0; i < 100; i++) {
      numbers.push(i);
  }

};
</script>

Preparation code output

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
Mustache
Mustache.render(mustacheTemplateSrc, {numbers: numbers});
pending…
Underscore
underscoreTemplate({numbers: numbers});
pending…

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

Compare results of other browsers

0 Comments