String.concat() vs. Array .join() vs. + operator (v4)

Revision 4 of this benchmark created on


Description

This testcase compares performance of string concatenation (+) versus the native Array.prototype.join() and String.prototype.concat() methods.

Preparation HTML

<script>
  var array = ["This", " is", " a", " very", " long", " string.", " Well,", " not", " that", " long", " I", " guess."];
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
String concat
var result = array[0] + array[1] + array[2] + array[3] + array[4] + array[5] + array[6] + array[7] + array[8] + array[9] + array[10] + array[11];
ready
Array.join
var result = array.join();
ready
individual concat
var result = '';
result += array[0];
result += array[1];
result += array[2];
result += array[3];
result += array[4];
result += array[5];
result += array[6];
result += array[7];
result += array[8];
result += array[9];
result += array[10];
result += array[11];
 
ready
String.concat
var result = String.prototype.concat.apply("", array);
ready

Revisions

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