Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0
Firefox 121
Windows
Desktop
one year ago
Test name Executions per second
Test Spread operator 15832545.0 Ops/sec
Test Object.create 1730335.1 Ops/sec
Test Object.assign 22896494.0 Ops/sec
Script Preparation code:
AخA
 
for (i = 0; i < 10; i++) {}
Tests:
  • Test Spread operator

     
    const firstObject = { 
        sampleData: 'Hello world',
        sampleMethod: () => { return true; }
    };
    const secondObject = {...firstObject};
  • Test Object.create

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

    x
     
    const firstObject = { 
        sampleData: 'Hello world',
        sampleMethod: () => { return true; }
    };
    const secondObject = Object.assign({}, firstObject);