Script Preparation code:
x
 
var firstObject = {
  "name": "John Doe",
  "age": 30,
  "isStudent": false,
  "address": {
    "street": "123 Main St",
    "city": "Anytown",
    "zipcode": "12345"
  },
  "contacts": [
    {
      "type": "email",
      "value": "john.doe@example.com"
    },
    {
      "type": "phone",
      "value": "+1 123-456-7890"
    }
  ],
  "skills": {
    "programming": ["JavaScript", "Python", "Java"],
    "design": ["Photoshop", "Illustrator"],
    "languages": {
      "spoken": ["English", "Spanish"],
      "written": ["English", "French"]
    }
  },
  "isActive": true,
  "projects": [
    {
      "name": "Project A",
      "status": "completed",
      "team": ["Alice", "Bob"]
    },
    {
      "name": "Project B",
      "status": "in progress",
      "team": ["Charlie", "David"]
    }
  ]
}
Tests:
  • Using the spread operator

     
    const finalObject = {...firstObject};
  • Using Object.assign

     
    const finalObject = Object.assign(firstObject);
  • forEach

     
    const finalObject = {}
    Object.keys(firstObject).forEach(key => {finalObject[key] = firstObject[key] })
  • deep clone

     
    function deepClone(original) {
      const cloned = {};
      Object.keys(original).forEach(key => {
        const value = original[key];
        if (typeof value === 'object' && value !== null) {
          // Recursively clone nested objects
          cloned[key] = deepClone(value);
        } else {
          // Copy non-object values directly
          cloned[key] = value;
        }
      });
      return cloned;
    }
    const finalObject = deepClone(firstObject);
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Using the spread operator
    Using Object.assign
    forEach
    deep clone

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one year ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36
Chrome 117 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
Using the spread operator 19153344.0 Ops/sec
Using Object.assign 10854715.0 Ops/sec
forEach 1855195.9 Ops/sec
deep clone 377658.8 Ops/sec