underscore.js template vs. string concatenation

JavaScript performance comparison

Test case created by Leandro López (inkel)

Preparation code

<script src="http://documentcloud.github.com/underscore/underscore-min.js">
Benchmark.prototype.setup = function() {
    var template = _.template("body.search #main, body.project #main, #sidebar { height: {{ height }}px }");
    var height   = 320;

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
string concatenation
"body.search #main, body.project #main, #sidebar { height: " + height + "px }";
underscore.js template
template({ height: height })

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