Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash cloneDeep vs generate new Object
(version: 0)
Comparing performance of:
deepClone vs generate
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
var generateObject = () => ({ description: 'Random description.', testNumber: 123456789, testBoolean: true, testObject: { testString: 'test string', testNumber: 12345 }, testArray: [{ myName: 'test name', myNumber: 123245 }] }); var testObject = { description: 'Random description.', testNumber: 123456789, testBoolean: true, testObject: { testString: 'test string', testNumber: 12345 }, testArray: [{ myName: 'test name', myNumber: 123245 }] } var testCopy = null;
Tests:
deepClone
testCopy = _.cloneDeep(testObject);
generate
testCopy = generateObject()
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
deepClone
generate
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
deepClone
800132.7 Ops/sec
generate
11204185.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to help you understand the JavaScript microbenchmark, MeasureThat.net. **Benchmark Definition** The benchmark is defined by two individual test cases: `deepClone` and `generate`. Both test cases compare two approaches to create a copy of an object. **Deep Clone (Lodash)** In the `deepClone` test case, Lodash's `cloneDeep` function is used to create a deep copy of the `testObject`. The `testCopy` variable is assigned the result of this function. A deep clone creates a new object with the same properties as the original object, but with separate values for each property. **Generate (New Object)** In the `generate` test case, a new object is created using an anonymous function (`var generateObject = () => { ... }`). This function returns a new object that mirrors the structure of the `testObject`, including its properties and nested objects. **Options Compared** Two options are compared: 1. **Lodash's cloneDeep**: Creates a deep copy of the object using Lodash's `cloneDeep` function. 2. **Generate New Object**: Creates a new object by mirroring the structure of the original object. **Pros and Cons** * **Lodash's cloneDeep**: + Pros: Efficiently creates a deep copy, preserving all nested objects and arrays. + Cons: Requires Lodash library to be included in the benchmark. * **Generate New Object**: + Pros: Simple, lightweight approach that creates a new object without requiring any libraries. + Cons: May not preserve nested objects or arrays correctly if they contain mutable values (e.g., arrays with dynamic lengths). **Library and Purpose** The Lodash library is used in this benchmark to provide the `cloneDeep` function, which creates deep copies of objects. The purpose of Lodash is to provide a set of utility functions for functional programming tasks, such as array manipulation, object transformation, and more. **Special JS Features or Syntax** This benchmark does not use any special JavaScript features or syntax. It's focused on comparing two simple approaches to create a copy of an object. **Other Alternatives** If Lodash is not available in the benchmark environment, alternative deep cloning libraries like `JSON.parse(JSON.stringify())` or custom implementations using recursion and object iteration could be used instead of Lodash's `cloneDeep`. Keep in mind that these alternatives may have performance implications compared to Lodash's optimized implementation.
Related benchmarks:
Lodash cloneDeep vs clone vs spread
ES6 vs Lodash object copying
Shallow clone array of objects
is lodash cloneDeep the BEST object deep cloner ? what about native structuredClone function ?
Lodash clone deep object array vs string array
Comments
Confirm delete:
Do you really want to delete benchmark?