String concatenation (v8)

Revision 8 of this benchmark created on


Description

Different ways to concatenate strings together

Preparation HTML

<script>
  var arr = ['a', 'b', 'c', 'd']
</script>

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 = arr.join('');
ready
Single individual statement
var foo = '';
foo += 'a' + 'b' + 'c' + 'd';
ready
Using "\" to wrap string (no concat)
var foo = "a \
b \
c \
d";
ready
template-style replacement
var foo = "1 2 3 4";
foo = foo.replace(/\d/g, function(match) {
 return arr[match];
});
ready

Revisions

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