Render Template From DOM Select vs Cache (v7)

Revision 7 of this benchmark created on


Description

This test was spawned by some discussion in a StackOverflow thread:

http://stackoverflow.com/questions/9833312/how-do-i-properly-store-a-javascript-template-so-that-it-isnt-instantiated-mul

The purpose is to test the speed of rendering an underscore.js template when selecting the template from the DOM every time, vs selecting it once and re-rendering the cached template every time.

Setup

this.cachedItem = $("#test-template");
    this.cachedTemplate = _.template(this.cachedItem.html());
    this.output = $("#html-output-goes-here");

Teardown


    delete this.cachedItem;
    delete this.cachedTemplate;
  

Test runner

Ready to run.

Testing in
TestOps/sec
Cached
var html = this.cachedTemplate();
this.output.html(html);
ready
Non-Cached
var uncachedItem = $("#test-template");
var uncachedTemplate = _.template(uncachedItem.html());
var html = uncachedTemplate();
this.output.html(html);
ready

Revisions

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