Run details:
Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/99.0
Firefox 99
Linux
Desktop
2 years ago
Test name Executions per second
Test Spread operator 880072.1 Ops/sec
Test Object.create 455075.4 Ops/sec
Test Object.assign 961230.9 Ops/sec
Test New Object 460826.4 Ops/sec
Script Preparation code:
x
 
for (i = 0; i < 10; i++) {
}
Tests:
  • Test Spread operator

     
    class firstObject {
      constructor() {
        this.sampleData = 'Hello world',
        this.sampleMethod = () => { return true; }
      }
    };
    const secondObject = {...firstObject};
    Object.setPrototypeOf(secondObject, Object.getPrototypeOf(firstObject));
  • Test Object.create

     
    class firstObject {
      constructor() {
        this.sampleData = 'Hello world',
        this.sampleMethod = () => { return true; }
      }
    };
    const secondObject = Object.create(Object.getPrototypeOf(firstObject), Object.getOwnPropertyDescriptors(firstObject));
  • Test Object.assign

     
    class firstObject {
      constructor() {
        this.sampleData = 'Hello world',
        this.sampleMethod = () => { return true; }
      }
    };
    const secondObject = Object.assign({}, firstObject);
    Object.setPrototypeOf(secondObject, Object.getPrototypeOf(firstObject));
  • Test New Object

     
    class firstObject {
      constructor() {
        this.sampleData = 'Hello world',
        this.sampleMethod = () => { return true; }
      }
    };
    const secondObject = new firstObject();