string concat vs array join

JavaScript performance comparison

Revision 36 of this test case created by

Preparation code

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.js"></script>

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

};

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

};
</script>

Preparation code output

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 (var i = 0, ni = arrayOfArrays.length; i < ni; i++) {
  dummy[i] = arrayOfArrays[i][0];
  for (var j = 1, nj = arrayOfArrays[i].length; j < nj; j++) {
    dummy[i] += " " + arrayOfArrays[i][j];
  }
}
pending…
Join
for (i = 0, j = arrayOfArrays.length; i < j; ++i) {
  dummy.push(arrayOfArrays[i].join(" "));
}
pending…
Functional
dummy = arrayOfArrays.map(function(e) {
  return e.reduce(function(a, b) {
    return a + " " + b
  })
})
pending…
Lodash functional
dummy = _.map(arrayOfArrays, function(e) {
  return _.reduce(e, function(a, b) {
    return a + " " + b
  })
})
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