ramda intersperse perf improvement

Benchmark created on


Setup

function current(separator, list) {
  var out = [];
  var idx = 0;
  var length = list.length;
  while (idx < length) {
    if (idx === length - 1) {
      out.push(list[idx]);
    } else {
      out.push(list[idx], separator);
    }
    idx += 1;
  }
  return out;
}

function next(separator, list) {
  var length = list.length;
  var out = Array(length * 2 - 1);
  var idx = 0;
  while (idx < length) {
    var i = idx * 2;
    if (idx === length - 1) {
      out[i] = list[idx];
    } else {
      out[i] = list[idx];
      out[i + 1] = separator;
    }
    idx += 1;
  }
  return out;
}

const arr = Array(1000).fill('a');

Test runner

Ready to run.

Testing in
TestOps/sec
Current
current(' ', arr)
ready
Next
next(' ', arr)
ready

Revisions

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