Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
reduce with object spread vs foreach with adding vs reduce without spread
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0
Browser:
Chrome 131
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Using reduce and the spread operator
608651.8 Ops/sec
Using map and adding to an object
6041884.0 Ops/sec
Using reduce without spread operator
6312028.5 Ops/sec
Tests:
Using reduce and the spread operator
const styles = { foo: { color: 'red', }, bar: { color: 'green', '&:focus': { color: 'blue', }, }, foo2: { color: 'red', }, bar2: { color: 'green', '&:focus': { color: 'blue', }, }, foo3: { color: 'red', }, bar3: { color: 'green', '&:focus': { color: 'blue', }, }, foo4: { color: 'red', }, bar4: { color: 'green', '&:focus': { color: 'blue', }, }, }; Object .keys(styles) .reduce((classes, selector) => ({ ...classes, [selector]: selector, }), {});
Using map and adding to an object
const styles = { foo: { color: 'red', }, bar: { color: 'green', '&:focus': { color: 'blue', }, }, foo2: { color: 'red', }, bar2: { color: 'green', '&:focus': { color: 'blue', }, }, foo3: { color: 'red', }, bar3: { color: 'green', '&:focus': { color: 'blue', }, }, foo4: { color: 'red', }, bar4: { color: 'green', '&:focus': { color: 'blue', }, }, }; const obj = {}; Object .keys(styles) .forEach(style => { obj[style] = style; })
Using reduce without spread operator
const styles = { foo: { color: 'red', }, bar: { color: 'green', '&:focus': { color: 'blue', }, }, foo2: { color: 'red', }, bar2: { color: 'green', '&:focus': { color: 'blue', }, }, foo3: { color: 'red', }, bar3: { color: 'green', '&:focus': { color: 'blue', }, }, foo4: { color: 'red', }, bar4: { color: 'green', '&:focus': { color: 'blue', }, }, }; Object .keys(styles) .reduce((classes, selector) => { classes[selector] = selector; return classes; }, {});