FP vs PROC

Benchmark created on


Setup

const myArr = [1, 2, 3, 4, 5, 6, 7, 8, 9]

function fp(arr) {
 return arr
 	.filter(num => num % 2)
  	.map(num => num * 2)
  	.reduce((acc, currVal) => acc + currVal, 0)
}

function proc(arr) {
	let total = 0
	for(let i = 0; i < arr.length; i++) {
  		const num = arr[i]
  		if(num % 2) {
    		total += num * 2
  		}
	}
	return total
}

function fpFlat(arr) {
  return arr
    .flatMap(num => num % 2 !== 0 ? [num * 2] : [])
    .reduce((acc, currVal) => acc + currVal, 0)
}

Test runner

Ready to run.

Testing in
TestOps/sec
FP
fp(myArr)
ready
PROC
proc(myArr)
ready
FP FLAT
fpFlat(myArr)
ready

Revisions

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