deep copy object (without functions) (v3)

Revision 3 of this benchmark created on


Setup

const t = [
  {
    "URL": "https://www.my.com/searchused.aspx",
    "prod": {
      "assetsCalls": ["a.js", "a.min.js"],
      "assetsCallCount": 2,
      "configResponseCode": 200,
      "configCallCount": 1,
      "pageLoadPayload": {
        "program": "",
        "Code": "boro",
        "wCode": "On",
        "pageType": "vlp",
        "experimental": {
          "version": ["1.27.3"]
        },
        "fullUrl": "https://www.my.com/searchused.aspx",
        "rank": "",
        "titlePage": "All Used Car Inventory"
      },
      "pageLoadCallCount": 1,
      "pageWsp": "On",
      "wspMatch": true,
      "qaapi": {
        "hits": [],
        "visit": {
          "result": [],
          "warnings": []
        },
        "offset": 0
      },
      "vdps": [
        {
          "assetsCalls": ["a.min.js", "a.min.js"],
          "assetsCallCount": 2,
          "configResponseCode": 200,
          "configWsp": "On",
          "configCallCount": 1,
          "pageLoadPayload": {
            "program": "",
            "Code": "boro",
            "wCode": "On",
            "pageType": "vdp",
            "vehicleType": "Used",
            "year": "2013",
            "make": "Toyota",
            "model": "Prius c",
            "bodyStyle": "5D Hatchback",
            "price": "14362",
            "fuelEconomy": "53mpg city, 46mpg hwy",
            "odometer": "103300 mi",
            "exteriorColor": "Orange",
            "experimental": {
              "json_ld": ["vehicleType,model,stockNumber,vin,exteriorColor,year,price,make"],
              "HTML_data": ["bodyStyle,fuelEconomy,odometer"],
              "version": ["1.27.3"]
            },
            "fullUrl": "https://www.my.com/used-Murfreesboro-2013-Toyota-Prius",
            "rank": "",
            "titlePage": ""
          },
          "pageLoadCallCount": 1,
          "pageWsp": "On",
          "wspMatch": true,
          "qaapi": {
            "hits": [],
            "visit": {
              "result": [],
              "warnings": []
            },
            "offset": 0
          },
          "url": "https://www.my.com/used-Murfreesboro-2013-Toyota-Prius"
        }
      ]
    },
    "nonProd": {
      "assetsCalls": ["a.min.js"],
      "assetsCallCount": 1,
      "configResponseCode": 200,
      "configWsp": "On",
      "configCallCount": 1,
      "pageLoadPayload": {
        "program": "",
        "Code": "boro",
        "wCode": "On",
        "pageType": "vlp",
        "experimental": {
          "version": ["1.27.3"]
        },
        "fullUrl": "https://www.my.com/searchused.aspx",
        "rank": "",
        "titlePage": "All Used Car Inventory"
      },
      "pageLoadCallCount": 1,
      "pageWsp": "On",
      "wspMatch": true,
      "qaapi": {
        "hits": [
          {
            "rawHit": {
              "result": {
                "hitUuid": "b583-4daf-a06a-24538641a74e",
                "eventTimestamp": 1663748411158,
                "rawPayload": "http://www.my.com/searchused.aspx&rn=51673830544&r=&t=All+Used+Car+Inventory+%7C",
                "rawHeaders": "Timeout-Access: <function1>\nX-Forwarded-For: 204.193.152.32, 23.1.32.212, 184.29.141.77\nX-Forwarded-Proto: https\nX-Forwarded-Port: 443\nHost: pixall-qa.esm1.net\nX-Amzn-Trace-Id: Root=1-632ac93b-279f182551858c2a3d36c5ea\nPragma: no-cache\nUser-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36\nAccept: image/avif, image/webp, image/apng, image/svg+xml, image/*, */*;q=0.8\nsec-fetch-site: cross-site\nsec-fetch-mode: no-cors\nsec-fetch-dest: image\nReferer: Cache-Control: no-cache, max-age=0"
              },
              "warnings": []
            },
            "sessionizedRawHit": {
              "result": {
                "payload": "http://my.com/v2/p?p=&v=RWbXmB7SbJxz8neiVCk3JjVT&d=boro&w=On&pt=vlp&x=version%3D1.27.3-SNAPSHOT-1663163915&u=https://www.my.com/searchused.aspx&rn=51673830544&r=&t=All+Used+Car+Inventory",
                "headers": "Timeout-Access: <function1>\nX-Forwarded-For: 204.193.152.32, 23.1.32.212, 184.29.141.77\nX-Forwarded-Proto: https\nX-Forwarded-Port: 443\nHost: pixall-qa.esm1.net\nX-Amzn-Trace-Id: Root=1-632ac93b-279f182551858c2a3d36c5ea\nPragma: no-cache\nUser-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36\nAccept: image/avif, image/webp, image/apng, image/svg+xml, image/*, */*;q=0.8\nsec-fetch-site: cross-site\nsec-fetch-mode: no-cors\nsec-fetch-dest: image\nReferer: https://www.toyotaofmurfreesboro.com/\nAccept-Language: it-IT, it;q=0.9\nCookie: pxa_ssn=1; abc=GHP5TgwfHt7a8oBtVtd76ejg; akaalb_pixall_nonprod=1663750162~op=Cache-Control: no-cache, max-age=0",
                "hitUuid": "9b5150b4-b583-4daf-a06a-24538641a74e",              
                "eventTimestamp": 1663748411158,
                "sessionId": "9b5150b4-b583-4daf-a06a-24538641a74e",
                "sessionTimestamp": 1663748411158
              },
              "warnings": []
            },
            "parsedHit": {
              "result": {
                "sessionId": "9b5150b4-b583-4daf-a06a-24538641a74e",
                "visitorId": "GHP5TgwfHt7a8oBtVtd76ejg",
                "hitUuid": "9b5150b4-b583-4daf-a06a-24538641a74e",
                "eventTimestamp": 1663748411158,
                "sessionTimestamp": 1663748411158,
                "url": "https://www.my.com/searchused.aspx",
                "urlParams": {},
                "experimental": {
                  "version": "1.27.3-SNAPSHOT-1663163915"
                },
                "Code": "boro",
                "accountId": "boro",
                "wCode": "On",
                "headers": "",
                "payload": "",
                "ipv4": "204.193.152.32",
                "domain": "my.com",
                "userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36",
                "pageType": "vlp",
                "program": "",
                "formConversion": false,
                "r1QueryParam": "",
                "titleTag": "All Used Car Inventory",
                "adGroup": "my",
                "isBot": false,
                "hitType": "page-view",
                "device": "Personal computer",
                  "lostAndFound": {}
              },
              "warnings": []
            }
          }
        ],
        "visit": {
          "result": [
            {
              
              "program": "",
              "accountId": "boro",
              "domain": "my.com",
              "startTimestamp": 1663748411158,
              "sessionTimestamp": 1663748411158,
              "endTimestamp": 1663748411158,
              "favoritesViewCount": 0,
              "Code": "boro",
              "wCode": "On",
              "formSubmissions": [],
              "userAgentRaw": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36",
              "userAgentType": "Browser",
              "ipv4": "204.193.152.32",
              "device": "Personal computer",
              "browserName": "Chrome",
              "browserVersion": "104.0.0.0",
              "operatingSystemName": "Linux",
              "operatingSystemVersion": "",
              "userRegistrationCount": 0,
              "pageViews": [
                {
                  "hitUuid": "9b5150b4-b583-4daf-a06a-24538641a74e",
                  "url": "https://www.my.com/searchused.aspx",
                  "pageType": "vlp",
                  "isManagedServices": false,
                  "time": 1663748411158,
                  "tracked": false
                }
              ],
              "contentEvents": [],
              "landingUrl": "https://www.my.com/searchused.aspx",
              "isBot": false,
              "isBlockedIpv4": false,
              "reserveItNowInitiated": false,
              "listingImpressions": [],
              "isAkamaiBot": false,
              "isFlagged": false,
              "isPersonalized": false,
            }
          ],
          "warnings": []
        },
        "offset": 1
      },
      "vdps": [
        {
          "assetsCalls": ["a.min.js", "a.min.js"],
          "assetsCallCount": 2,
          "configResponseCode": 200,
          "configWsp": "On",
          "configCallCount": 1,
          "pageLoadPayload": {
            "program": "",
            "Code": "boro",
            "wCode": "On",
            "pageType": "vdp",
            "year": "2013",
            "make": "Toyota",
            "model": "Prius c",
            "bodyStyle": "5D Hatchback",
            "stockNumber": "P10159",
            "fuelEconomy": "53mpg city, 46mpg hwy",
            "exteriorColor": "Orange",
            "experimental": {
              "json_ld": ["vehicleType,model,stockNumber,vin,exteriorColor,year,price,make"],
              "HTML_data": ["bodyStyle,fuelEconomy,odometer"],
              "version": ["1.27.3"]
            },
            "fullUrl": "https://www.my.com/used-Murfreesboro-2013",
            "rank": "",
            "titlePage": "2013 Toyota Priu"
          },
          "pageLoadCallCount": 1,
          "pageWsp": "On",
          "wspMatch": true,
          "qaapi": {
            "hits": [],
            "visit": {
              "result": [],
              "warnings": []
            },
            "offset": 0
          },
          "url": "https://www.my.com/used-Murfreesboro-2013-Toyota7"
        }
      ]
    }
  }
]

Test runner

Ready to run.

Testing in
TestOps/sec
deepcopy json.parse
JSON.parse(JSON.stringify(t));
ready
deepcopy custom function
function deepCopy(o) {
  let newobject = {};
  if (o !== undefined && o !== null && o.constructor)
    newobject = new o.constructor();
  return typeof o === 'object' && o !== null ?      // only clone objects
    (Array.isArray(o) ?                        // if cloning an array
        o.map(e => deepCopy(e)) :                   // clone each of its elements
        Object.keys(o).reduce(                   // otherwise reduce every key in the object
          (r, k) => (r[k] = deepCopy(o[k]), r), newobject  // and save its cloned value into a new object
        )
    ) :
    o;                                         // return non-objects as is
}
deepCopy(t)
ready

Revisions

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