Lodash cloneDeep vs structuredClone

Benchmark created on


Preparation HTML

<!--
<script src="
https://cdn.jsdelivr.net/npm/lodash/lodash.min.js
"></script>

<script type="module">
import lodash from 'https://cdn.jsdelivr.net/npm/lodash/+esm'
</script>
-->

<script type="module">
import lodash from 'https://cdn.jsdelivr.net/npm/lodash/+esm'
window.lodash = lodash
</script>

Setup

const objSimple = {
  description: 'Creates a deep copy of source, which should be an object or an array.',
  myNumber: 123456789,
  myBoolean: true,
  jayson: {
    stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....',
    parse: 'JSON.parse() method parses a JSON string...'
  }
};

const objBig = {
  emails: [
    {
      type: "work",
      value: "example@example.com",
    },
  ],
  preferredLanguage: "",
  meta: {
    created: "2025-05-17T22:25:52Z",
    location:
      "https://example.com/Users/1234567890",
    lastModified: "2025-10-22T22:12:30Z",
    resourceType: "User",
  },
  schemas: [
    "urn:ietf:params:scim:schemas:core:2.0:User",
    "urn:ietf:params:scim:schemas:extension:ibm:2.0:User",
  ],
  name: {
    formatted: "First Last",
    familyName: "Last",
    givenName: "First",
  },
  "urn:ietf:params:scim:schemas:extension:ibm:2.0:User": {
    lastLogin: "2025-10-22T22:12:30Z",
    lastLoginRealm: "loginRealm",
    lastMFA: [
      {
        type: "emailotp",
        value: "2025-06-11T16:10:56Z",
      },
      {
        type: "fido2",
        value: "2025-08-30T18:23:15Z",
      },
    ],
    userCategory: "regular",
    twoFactorAuthentication: false,
    linkedAccounts: [
      {
        externalId: "userName123",
        realm: "saml2",
      },
    ],
    realm: "cloudIdentityRealm",
    pwdChangedTime: "2025-05-17T23:38:52Z",
    lastLoginType: "user_password",
  },
  groups: [
    {
      displayName: "admin",
      id: "1234567890",
      $ref: "https://example.com/Groups/1234567890",
      value: "1234567890",
    },
  ],
  active: true,
  id: "1234567890",
  userName: "userName123",
}


const arr = [1, 2, { pos: 3 }, 4, 5]
const objComplex = {
  myDate: new Date(),
  myDate2: new Date(),
  now: Date.now(),
  arr,
  arr2: arr,
  description: 'Creates a deep copy of source, which should be an object or an array.',
  myNumber: 123456789,
  myBoolean: true,
  jayson: {
    stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....',
    parse: 'JSON.parse() method parses a JSON string...'
  }
};

let objCopy = null;

Test runner

Ready to run.

Testing in
TestOps/sec
simple: cloneDeep
objCopy = lodash.cloneDeep(objSimple);
ready
simple: structuredClone
objCopy = structuredClone(objSimple);
ready
big: cloneDeep
objCopy = lodash.cloneDeep(objBig);
ready
big: structuredClone
objCopy = structuredClone(objBig);
ready
complex: cloneDeep
objCopy = lodash.cloneDeep(objComplex);
ready
complex: structuredClone
objCopy = structuredClone(objComplex);
ready

Revisions

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