Render Template From DOM Select vs Cache

JavaScript performance comparison

Revision 3 of this test case created by

Preparation code

<script id="test-template" type="text/template">
  <p>
    this is <div class="foo">some html</div>
  </p>
  <ul>
    <li>with data
    <li>and items
    <li>etc
  </ul>
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="https://documentcloud.github.com/underscore/underscore-min.js"></script>
<div id="html-output-goes-here"></div>
      
<script>
Benchmark.prototype.setup = function() {
  this.cachedItem = $("#test-template");
  this.cachedTemplate = _.template(this.cachedItem.html());
  this.output = $("#html-output-goes-here");

};

Benchmark.prototype.teardown = function() {
  delete this.cachedItem;
  delete this.cachedTemplate;

};
</script>

Preparation code output

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script src="https://documentcloud.github.com/underscore/underscore-min.js"></script> <div id="html-output-goes-here"></div>

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
Cached
var html = this.cachedTemplate();
this.output.html(html);
console.log('a');
pending…
Non-Cached
var uncachedItem = $("#test-template");
var uncachedTemplate = _.template(uncachedItem.html());
var html = uncachedTemplate();
this.output.html(html);
console.log('b');
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