Change object pointer by spread vs assign()

Benchmark created on


Setup

let object = {foo: 'bar'}
let newValue = {foo: 'baz'}

Test runner

Ready to run.

Testing in
TestOps/sec
Same object spread
object = {...object}
ready
Same object assign
object = Object.assign({}, object)
ready
New value spread
object = {...newValue}
ready
New value assign
object = Object.assign({}, newValue)
ready
Merge objects spread
object = {...object, ...newValue}
ready
Merge objects assign
object = Object.assign({}, object, newValue)
ready
[Etalon] Don't change pointer
Object.assign(object, newValue)
ready

Revisions

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