String concat methods test

JavaScript performance comparison

Test case created by JFM

Info

test of various string concatenation methods

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var letters = "abcdefghijklmnopqrstuvwxyz".split('');
};
</script>

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];
}
pending…
For concat
var s = '';
for (var i = 0; i < letters.length; i++) {
  s = s.concat(letters[i]);
}
pending…
Join
var s = letters.join();
pending…

Compare results of other browsers

Revisions

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 ?

Add a comment