Object assign vs Object spread

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
Object.assign
const state = { a: 1, b: 2, c: 3, d: 4, e: 5 };

console.time('Object.assign');
for (let i = 0; i < 100000; i++) {
    const nextState = Object.assign({}, state);
}
console.timeEnd('Object.assign');
ready
Spread operator
const state = { a: 1, b: 2, c: 3, d: 4, e: 5 };

console.time('Spread operator');
for (let i = 0; i < 100000; i++) {
    const nextState = { ...state };
}
console.timeEnd('Spread operator');
ready

Revisions

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