ramda scan perf improvement

Benchmark created on


Setup

function current(fn, acc, list) {
  var idx = 0;
  var len = list.length;
  var result = [acc];
  while (idx < len) {
    acc = fn(acc, list[idx]);
    result[idx + 1] = acc;
    idx += 1;
  }
  return result;
}

function next(fn, acc, list) {
  var idx = 0;
  var len = list.length;
  var result = Array(len + 1);
  result[0] = acc;
  while (idx < len) {
    acc = fn(acc, list[idx]);
    result[idx + 1] = acc;
    idx += 1;
  }
  return result;
}

const arr = Array(10000).fill(undefined).map((_, i) => i);

Test runner

Ready to run.

Testing in
TestOps/sec
Current
current((i, acc) => acc + i, 0, arr)
ready
Next
next((i, acc) => acc + i, 0, arr)
ready

Revisions

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