flatMap vs reducedddd
Date tested:
2 years ago
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36 OPR/79.0.4143.50
Test name
Executions per second
reduce with concat
17157.4 Ops/sec
flatMap
501.7 Ops/sec
Benchmark definition (click to collapse):
Script Preparation code:
var arr = Array(10_000).fill(0)
Tests:
reduce with concat
arr.reduce((acc, x) => { acc.push(x) return acc }, [])
flatMap
arr.flatMap(x => { return [x] })
Open this result on MeasureThat.net