For testing .reduce
variants. Inspired by noAccumulatingSpread.
- Install Node.js v22+
- Install deps:
npm i
- Run it:
npm run dev
Each variant does the same thing: it maps 300k rows to an object.
Notice how withReduceSpreadAccumulator
takes way longer than the other variants.
Ran on a 2021 MacBook Pro Apple M1 Max. Your results may vary.
withForOf: 17.737ms
withFilterAndMapAndFromEntries: 15.524ms
withReduceMutateAccumulator: 8.428ms
withReduceSpreadAccumulator: 31.500s