Concatenation vs Array Join

JavaScript performance comparison

Revision 10 of this test case created

Preparation code

<script>
  var str, str1, i, j;
</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
for (i = 0; i < 10000; i++) {
  str += 'a';
}
pending…
Array.prototype.join
var tmp = [];
for (j = 0; j < 10000; j++) {
  tmp.push('a');
}
str2 = tmp.join('');
pending…
var tmp = [];
var str2 = "";
for (j = 0; j < 10000; j++) {
  tmp.push('a');
  if (j == 500) {
    str2 += tmp.join('');
    tmp = [];
  }
}
str2 += tmp.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:

0 comments

Add a comment