for vs filter map vs reduce

Benchmark created on


Setup

const DATA = [...Array(1000).keys()];

Test runner

Ready to run.

Testing in
TestOps/sec
For of
const acc = [];
for (const i of DATA) {
  if (i >= 99) {
    continue;
  }
  acc.push(i + 1);
}
ready
Reduce
DATA.reduce((acc, i) => {
  if (i >= 99) {
    return acc;
  }
  acc.push(i + 1);
  return acc;
}, []);
ready
Map + filter
DATA.filter((i) => i < 99).map((i) => i + 1);
ready

Revisions

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