Reduce vs Filter

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
Reduce
const numbers = []
const config = [
  2, 3, 5, 6, 15,
]
for (let i = 0; i < 10 ** 5; i += 1) {
  numbers.push(i)
}

numbers.reduce((prev, current) => config.every((divisor) => current % divisor === 0) ? prev.concat(current) : prev, [])
ready
Filter
const numbers = []
const config = [
  2, 3, 5, 6, 15,
]
for (let i = 0; i < 10 ** 5; i += 1) {
  numbers.push(i)
}

numbers.filter((current) => config.every((divisor) => current % divisor === 0))
ready

Revisions

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