String concatenation (v39)

Revision 39 of this benchmark created on


Description

Different ways to concatenate strings together

Setup

var a = 'a';
    var c = ('' + Math.random().toFixed(20));

Test runner

Ready to run.

Testing in
TestOps/sec
Direct concatenation
var foo = a + 'b' + c + 'd';
ready
Individual += statements
var foo = a;
foo += 'b';
foo += c;
foo += 'd';
ready
Individual statements
var foo = a;
foo = foo + 'b';
foo = foo + c;
foo = foo + 'd';
ready
Using Array#join
var foo = [a, 'b', c, 'd'].join('');
ready
RegEx stache replacement
var foo = "{{a}}b{{c}}d".replace(/{{a}}/, a).replace(/{{c}}/, c);
ready
Comma Operator
var foo = a;
(foo += 'b', foo += c, foo += 'd');
ready
Concat
var foo = a;
foo = foo.concat('b');
foo = foo.concat(c);
foo = foo.concat('d');
ready

Revisions

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