String concatenation

JavaScript performance comparison

Revision 39 of this test case created

Info

Different ways to concatenate strings together

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var a = 'a';
    var c = ('' + Math.random().toFixed(20));
};
</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
Direct concatenation
var foo = a + 'b' + c + 'd';
pending…
Individual += statements
var foo = a;
foo += 'b';
foo += c;
foo += 'd';
pending…
Individual statements
var foo = a;
foo = foo + 'b';
foo = foo + c;
foo = foo + 'd';
pending…
Using Array#join
var foo = [a, 'b', c, 'd'].join('');
pending…
RegEx stache replacement
var foo = "{{a}}b{{c}}d".replace(/{{a}}/, a).replace(/{{c}}/, c);
pending…
Comma Operator
var foo = a;
(foo += 'b', foo += c, foo += 'd');
pending…
Concat
var foo = a;
foo = foo.concat('b');
foo = foo.concat(c);
foo = foo.concat('d');
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