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">
</script>
<script>
Benchmark.prototype.setup = function() {
    var template = _.template("body.search #main, body.project #main, #sidebar { height: {{ height }}px }");
    var height   = 320;
};
</script>

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 }";
pending…
underscore.js template
template({ height: height })
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. Here’s a list of current revisions for this page:

0 comments

Add a comment