string concat vs array join

JavaScript performance comparison

Revision 35 of this test case created by Helder Magalhães

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var arrayOfArrays = [ [123, "XY"], [345, "z"], [456, "K"] ];
  var dummy; //just to force attribution

};

Benchmark.prototype.teardown = function() {
  arrayOfArrays = dummy = null;

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Concat
for(i = 0, j = arrayOfArrays.length; i < j; ++i) {
  dummy = arrayOfArrays[i][0] + " " + arrayOfArrays[i][1];
}
pending…
Concat (by parts)
for(i = 0, j = arrayOfArrays.length; i < j; ++i) {
  dummy = arrayOfArrays[i][0];
  dummy += " ";
  dummy +=arrayOfArrays[i][1];
}
pending…
Join
for(i = 0, j = arrayOfArrays.length; i < j; ++i) {
  dummy = arrayOfArrays[i].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.

0 Comments