Concatenation vs Array Join

JavaScript performance comparison

Revision 8 of this test case created by Leonardo Dutra

Preparation code

<script>
  var i, str;
</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
Concatenation: string + string
str = '';
i = 0;
while (i++ < 100) {
 str += 'a';
}
pending…
Buffer: Array.prototype.join
str = [];
i = 0;
while (i < 100) {
 str[i++] = 'a';
}
str = str.join('');
pending…
String index: 'string'[index]
// This has compatibility issues (mainly IE)
str = '';
i = 0;
while (i < 100) {
 str[i++] = 'a';
}
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:

0 comments

Add a comment