Reduce with spread

Benchmark created on


Setup

function generateLargeObject(numKeys) {
    const obj = {};
    for (let i = 0; i < numKeys; i++) {
        obj[`key${i}`] = i;
    }
    return obj;
}


const numKeys = 400;
const largeObject = generateLargeObject(numKeys);

Test runner

Ready to run.

Testing in
TestOps/sec
reduce with spread


Object.keys(largeObject).reduce((accumulator, key) => {
        return {
            ...accumulator,
            [key]: largeObject[key]
        };
    }, {});


ready
no spread
var result = {};

for (const [key, value] of Object.entries(largeObject)) {
  result[key] = Object.prototype.hasOwnProperty.call(value, 'value') ? value['value'] : value;
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.