map filter vs reduce

Benchmark created on


Setup

const data = Array.from(Array(100).keys()).map((v,index) => ({index: index, name: index % 5 === 0 ? 'x-read-more' : 'test' }))

Test runner

Ready to run.

Testing in
TestOps/sec
reduce
data.reduce((arr, obj) => {
	if(obj.name === 'x-read-more') {
		arr.push(obj.index)
	}
	return arr
}, [])
ready
filter map
data
  .filter(obj => obj.name === 'x-read-more')
  .map(obj => obj.index)
ready

Revisions

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