string concat vs array join (v36)

Revision 36 of this benchmark created on


Preparation HTML

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

Setup

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

Teardown



            arrayOfArrays = dummy = null;
        
  

Test runner

Ready to run.

Testing in
TestOps/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];
  }
}
ready
Join
for (i = 0, j = arrayOfArrays.length; i < j; ++i) {
  dummy.push(arrayOfArrays[i].join(" "));
}
ready
Functional
dummy = arrayOfArrays.map(function(e) {
  return e.reduce(function(a, b) {
    return a + " " + b
  })
})
ready
Lodash functional
dummy = _.map(arrayOfArrays, function(e) {
  return _.reduce(e, function(a, b) {
    return a + " " + b
  })
})
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.