String concatenation (v52)

Revision 52 of this benchmark created on


Description

Different ways to concatenate strings together

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
Single individual statement
var foo = 'a';
foo += 'b' + 'c' + 'd';
ready
Function based (for)
function concat(arr) {
  len = arr.length;
  for (s = "", i = 0; i < len; s += arr[i], i++);
  return s;
}

var foo = concat(['a', 'b', 'c', 'd']);
ready
concat method
var foo = 'a';
foo.concat('b', 'c', 'd');
ready

Revisions

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