String concatenation Mobile phones (v57)

Revision 57 of this benchmark created on


Description

PLEASE RUN TEST ON MOBILE PHONES ONLY Different ways to concatenate strings together.

Preparation HTML

<script>
  var str1 = "abcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefga";

  var str2 = "abcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefg";

  var str3 = "abcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefg";

  var str4 = "abcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefg";

  var arr = [str1, str2, str3, str4];

  var concat = function (arr) {
    var len = arr.length, s, i;
    for (s = "", i = 0; i < len; s += arr[i], i++);
    return s;
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Direct concatenation
var foo = str1 + str2 + str3 + str4;
ready
Individual += statements
var foo = str1;
foo += str2;
foo += str3;
foo += str4;
ready
Individual statements
var foo = str1;
foo = foo + str2;
foo = foo + str3;
foo = foo + str4;
ready
Using Array#join
var foo = arr.join('');
ready
Single individual statement
var foo = str1;
foo += str2 + str3 + str4;
ready
Function based (for)
var foo = concat(arr);
ready
concat
var foo = str1;
foo = foo.concat(str2);
foo = foo.concat(str3);
foo = foo.concat(str4);
ready
direct concat
var foo = str1.concat(str2, str3, str4);
ready

Revisions

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