Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
reduce with spread vs flatMap vs reduce with push
reduce with spread vs flatMap vs reduce with push
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Browser:
Chrome 124
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
reduce
5002495.5 Ops/sec
flatMap
3674951.2 Ops/sec
Script Preparation code:
const mockedObject = { a: { values: ['test1, test2, test3, test4'] }, b: { values: '' }, c: { values: [] } };
Tests:
reduce
const mockedObject = { a: { values: ['test1, test2, test3, test4'] }, b: { values: '' }, c: { values: [] } }; Object.entries(mockedObject).reduce((acc, curr) => { const [key, props] = curr; if (!props.values) return acc; return [...acc, props.values]; }, []);
flatMap
const mockedObject = { a: { values: ['test1, test2, test3, test4'] }, b: { values: '' }, c: { values: [] } }; Object.entries(mockedObject).flatMap(([key, props]) => { if (!props.values) return []; return props.values; });