Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
for in or reduce
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/126.0.0.0 Safari/537.36
Browser:
Chrome 126
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
forInFunc
113987.4 Ops/sec
funcReduce
88627.1 Ops/sec
Script Preparation code:
var testInitialConfig = { key1: 123, key2: [], key3: { a: 123 } }; var testOverrideConfig = { key1: 'abc', key3: { a: [] } }; var funcReduce = (initialConfig, overrideConfig) => { if (!overrideConfig) { return { ...initialConfig }; } const keys = Object.keys(initialConfig); return keys.reduce( (acc, key) => { if (overrideConfig[key]) { return { ...acc, [key]: { ...initialConfig[key], ...overrideConfig[key], }, }; } return acc; }, { ...initialConfig }, ); }; var forInFunc = (initialConfig, overrideConfig) => { const mergedConfig = { ...initialConfig }; if (!overrideConfig) { return mergedConfig; } for (const keyString in initialConfig) { const key = keyString; if (overrideConfig[key]) { mergedConfig[key] = { ...initialConfig[key], ...overrideConfig[key], }; } } return mergedConfig; };
Tests:
forInFunc
const result1 = forInFunc(testInitialConfig, testOverrideConfig) console.log(result1)
funcReduce
const result2 = funcReduce(testInitialConfig, testOverrideConfig) console.log(result2)