Concatenation vs Array Join

JavaScript performance comparison

Revision 19 of this test case created by Qantas94Heavy

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
      var i,
          str,
          tmp = [],
          cnt = 10000;
};
</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 1
for (i = 0, str = ''; i < cnt; ++i) {
  str += 'a';
}
pending…
Array.prototype.join 1
for (i = 0, tmp.length = 0; i < cnt; ++i) {
    tmp.push('a');
}
str = tmp.join('');
pending…
Array.prototype.join 2
for (i = 0, tmp.length = 0; i < cnt; i++) {
 tmp[i] = 'a';
}

str = 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