Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36
Chrome 116
Mac OS X 10.15.7
Desktop
one year ago
Test name Executions per second
Using the spread operator 53555956.0 Ops/sec
Using Object.assign 7634575.0 Ops/sec
Tests:
  • Using the spread operator

    x
     
    const firstObject = {
      attempts: 1,
      created_at: 1694778031091,
      expires_at: 1694778091091,
      source: {
        externalId: "831f76fc-5a9d-49bc-8d4b-114010cedb73",
        name: "Tengen Uzui",
        type: "phone",
      },
      type: "phone",
      value: "411273",
    };
    const finalObject = {
      ...firstObject,
      attempts: firstObject.attempts + 1,
    };
  • Using Object.assign

     
    const firstObject = {
      attempts: 1,
      created_at: 1694778031091,
      expires_at: 1694778091091,
      source: {
        externalId: "831f76fc-5a9d-49bc-8d4b-114010cedb73",
        name: "Tengen Uzui",
        type: "phone",
      },
      type: "phone",
      value: "411273",
    };
    const finalObject = Object.assign({}, firstObject, {
      attempts: firstObject.attempts + 1,
    });