Ramda _concat perf improvement (v2)

Revision 2 of this benchmark created on


Setup

function _current(set1, set2) {
  set1 = set1 || [];
  set2 = set2 || [];
  var idx;
  var len1 = set1.length;
  var len2 = set2.length;
  var result = [];

  idx = 0;
  while (idx < len1) {
    result[result.length] = set1[idx];
    idx += 1;
  }
  idx = 0;
  while (idx < len2) {
    result[result.length] = set2[idx];
    idx += 1;
  }
  return result;
}

function _next(set1, set2) {
  set1 = set1 || [];
  set2 = set2 || [];
  var idx;
  var len1 = set1.length;
  var len2 = set2.length;
  var result = Array(len1 + len2);

  idx = 0;
  while (idx < len1) {
    result[idx] = set1[idx];
    idx += 1;
  }
  idx = 0;
  while (idx < len2) {
    result[len2 + idx] = set2[idx];
    idx += 1;
  }
  return result;
}

var arr1 = [];
for (i = 0; i < 1000; i++) {
  arr1[i] = i;
}
var arr2 = [];
for (i = 2000; i < 3000; i++) {
  arr2[i] = i;
}

Test runner

Ready to run.

Testing in
TestOps/sec
Current Ramda
_current(arr1, arr2);
ready
With preset array length
_next(arr1, arr2);
ready
Native
arr1.concat(arr2);
ready
Spread
[...arr1, ...arr2]
ready

Revisions

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