DOM vs innerHTML based Templating

JavaScript performance comparison

Revision 418 of this test case created by Sergey Kononenko


A brief comparison of some JavaScript templating engines on a short template: 7 DOM nodes ... 7 interpolated values.

Preparation code

<script src=""></script>

<script src=""></script>

<script src=""></script>

<script src=""></script>

<script type="text/javascript" src="">

<script type="text/javascript" src="">

<script type="text/javascript" src="">

<script type="text/javascript" src="">

<div id="mustache"></div>

<div class="purejs_template">
  <h1 class="header"></h1>
  <div class='a'></div>
  <div class='b'></div>
  <div class='c'></div>
  <div class='d'></div>
  <div class='e'></div>
  <div class='f'></div>

<div id="underscore"></div>

<div id="tuna">
  <h1 class="t-header"></h1>
  <div class='t-a'></div>
  <div class='t-b'></div>
  <div class='t-c'></div>
  <div class='t-d'></div>
  <div class='t-e'></div>
  <div class='t-f'></div>

<div xmlns:tuna style="display: none;">
<tuna:template id="template">
  <tuna:spot tuna:target="t-header" tuna:path="header" />
  <tuna:spot tuna:target="t-a" tuna:path="a" />
  <tuna:spot tuna:target="t-b" tuna:path="b" />
  <tuna:spot tuna:target="t-c" tuna:path="c" />
  <tuna:spot tuna:target="t-d" tuna:path="d" />
  <tuna:spot tuna:target="t-e" tuna:path="e" />
  <tuna:spot tuna:target="t-f" tuna:path="f" />


  window.mustacheTemplate = "<div><h1 class='header'>{{header}}</h1><div class='a'>{{a}}</div><div class='b'>{{b}}</div><div class='c'>{{c}}</div><div class='d'>{{d}}</div><div class='e'>{{e}}</div><div class='f'>{{f}}</div></div>";
  window.underscoreTemplate = _.template("<div><h1 class='header'><%=header%></h1><div class='a'><%=a%></div><div class='b'><%=b%></div><div class='c'><%=c%></div><div class='d'><%=d%></div><div class='e'><%=e%></div><div class='f'><%=f%></div></div>");
  window.sharedVariables = {
   header: "Header",
   a: 'aaa',
   b: 'bbb',
   c: 'ccc',
   d: 'ddd',
   e: 'eee',
   f: 'fff'

  var mustacheContainer = document.getElementById("mustache");
  var underscoreContainer = document.getElementById("underscore");

  var tunaContainer = document.getElementById('tuna');
  var template = tuna.tmpl.compileFromMarkup(tunaContainer, 'template');

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
Mustache.js Template
mustacheContainer.innerHTML = Mustache.to_html(mustacheTemplate, sharedVariables);
Pure JS Template
Underscore.js Template
underscoreContainer.innerHTML = underscoreTemplate(sharedVariables);
Tuna Templates

Compare results of other browsers


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:


Comment form temporarily disabled.

Add a comment