Native filter vs Katamari filter

Benchmark created on


Setup

const filter = (xs, pred) => {
  const r = [];
  for (let i = 0, len = xs.length; i < len; i++) {
    const x = xs[i];
    if (pred(x, i)) {
      r.push(x);
    }
  }
  return r;
};

const data = Array.from({ length: 30000 }, (_, i) => i + 1);

Test runner

Ready to run.

Testing in
TestOps/sec
Native array filter
data.filter((x) => x % 2 === 0)
ready
Katamari array filter
filter(data, (x) => x % 2 === 0)
ready

Revisions

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