Cloning Objects (v3)

Revision 3 of this benchmark created on


Description

How to clone object comparison

Setup

const person = {
  name: 'John Doe',
  age: 34,
  address: {
    country: 'USA',
    city: 'Boston',
  },
  hobbies: ['Reading', 'Cooking'],
  active: true,
  signDate: new Date(),
//   superPowers: new Set(['strength', 'fly']),
//  knwoledge: new Map([['history', 'good'], ['math', 'bad']]),
};

Test runner

Ready to run.

Testing in
TestOps/sec
destructuring
let shallowCopy;
for (let i = 0; i < 100000; i++) {
  shallowCopy = { ...person };
}
ready
Object.assign
let assignCopy;
for (let i = 0; i < 100000; i++) {
  assignCopy = Object.assign({}, person);
}
ready

Revisions

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