String concatenation (v25)

Revision 25 of this benchmark created by Hans on


Description

Different ways to concatenate strings together

Preparation HTML

<script>
  var value = 4;
  var text = ["Privjyet", 4];
  var arr = ['<option value="', value, '">', text, '</option>']
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Direct concatenation
var foo = '<option value="' + value + '">' + text + '</option>';
ready
Individual += statements
var foo = '<option value="';
foo += value;
foo += '">';
foo += text;
foo += '</option>';
ready
Individual statements
var foo = '<option value="';
foo = foo + value;
foo = foo + '">';
foo = foo + text;
foo = foo + '</option>';
ready
Using Array#join
var foo = arr.join('');
ready
Single individual statement
var foo = '<option value="';
foo += value + '">' + text + '</option>';
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(arr);
ready

Revisions

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