String concat methods test

JavaScript performance comparison

Test case created by JFM


test of various string concatenation methods

Preparation code

Benchmark.prototype.setup = function() {
    var letters = "abcdefghijklmnopqrstuvwxyz".split('');

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
For +
var s = '';
for (var i = 0; i < letters.length; i++) {
  s += letters[i];
For concat
var s = '';
for (var i = 0; i < letters.length; i++) {
  s = s.concat(letters[i]);
var s = letters.join();

Compare results of other browsers


You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

1 comment

SteveP commented :

Thanks for this analytical approach to answering the question of string concatenation performance. I wonder if the individual chunk sizes make any difference to the performance though - would it be possible to incorporate larger chunk sizes (say 100 bytes / 1K bytes/ 10K bytes) into the tests to see if basic + operator is still the quickest ?

Comment form temporarily disabled.

Add a comment