Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
for vs. for-in vs. for-of vs. reduce (map object values)
Make a new object by applying a function to each value of the source object.
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Mobile Safari/537.36 EdgA/126.0.0.0
Browser:
Chrome Mobile 126
Operating system:
Android
Device Platform:
Mobile
Date tested:
one year ago
Test name
Executions per second
for loop
397633.6 Ops/sec
for-in loop
465685.9 Ops/sec
for-of loop
399500.9 Ops/sec
reduce
210743.0 Ops/sec
Script Preparation code:
var source = { "box-sizing": "border-box", "margin": 0, "padding": 0, "border-width": 0, "border-style": "solid", "border-color": "#ddd" } function iteratee(value) { return `${value} !important` }
Tests:
for loop
const sourceKeys = Object.keys(source) const result = {} for (let i = 0; i < sourceKeys.length; i++) { result[sourceKeys[i]] = iteratee(source[sourceKeys[i]]) }
for-in loop
const result = {} for (const key in source) { result[key] = iteratee(source[key]) }
for-of loop
const result = {} for (const key of Object.keys(source)) { result[key] = iteratee(source[key]) }
reduce
const result = Object.keys(source).reduce((memo, key) => { return { ...memo, [key]: iteratee(source[key]) } }, {})