Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash cloneDeep vs Object create
(version: 0)
compare array copy/clone methods
Comparing performance of:
Lodash cloneDeep vs Object.create deep clone
Created:
5 years ago
by:
Registered User
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 testObject = { description: 'Random description.', testNumber: 123456789, testBoolean: true, testObject: { testString: 'test string', testNumber: 12345 }, testArray: [{ myName: 'test name', myNumber: 123245 }] }; var testCopy = null;
Tests:
Lodash cloneDeep
testCopy = _.cloneDeep(testObject);
Object.create deep clone
testCopy = Object.create(testObject);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash cloneDeep
Object.create deep clone
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
8 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Browser/OS:
Chrome 139 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash cloneDeep
697565.2 Ops/sec
Object.create deep clone
9294131.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and its options. **What is tested:** The benchmark compares two methods for creating a deep copy of an object: 1. `_.cloneDeep` from Lodash (a popular JavaScript utility library) 2. `Object.create` These methods are used to create a new, independent copy of the test object (`testObject`). The test object contains nested objects and arrays. **Options compared:** The benchmark compares two options: 1. **Lodash cloneDeep**: This method uses Lodash's `cloneDeep` function to create a deep copy of the object. 2. **Object.create**: This method creates a new object using the `Object.create()` constructor, passing the original object as an argument. **Pros and Cons:** **Lodash cloneDeep:** Pros: * Widely used and tested library * Provides a simple and efficient way to create deep copies of objects * Supports various data types (arrays, objects, etc.) Cons: * Adds extra dependencies (Lodash) * May have slower performance due to the overhead of a library **Object.create:** Pros: * Native JavaScript implementation * Fast and lightweight * No additional dependencies required Cons: * Requires manual configuration and handling of prototype chains * Less flexible than Lodash's cloneDeep approach **Other considerations:** When using `Object.create`, it's essential to be aware that the resulting object is a shallow copy, meaning that any properties added to the new object will only inherit from the original object's prototype chain. If you need to create a deep copy with all nested objects and arrays also copied, this approach may not suffice. **Library: Lodash** Lodash is a popular JavaScript utility library that provides various functions for tasks like array manipulation, object creation, and more. `cloneDeep` is one of its most useful functions, which creates a deep copy of an object, handling nested objects and arrays. **Special JS feature or syntax: None mentioned in the benchmark** Now, let's take a look at the individual test cases: 1. **Lodash cloneDeep**: This test case uses Lodash's `cloneDeep` function to create a deep copy of the `testObject`. 2. **Object.create deep clone**: This test case uses the `Object.create()` constructor to create a new object that inherits from the original `testObject`. However, as mentioned earlier, this method only creates a shallow copy. In summary, the benchmark compares two methods for creating deep copies of objects: Lodash's `cloneDeep` and `Object.create`. While both options have their pros and cons, Lodash's cloneDeep is a widely used and efficient solution that requires no additional dependencies.
Related benchmarks:
Lodash cloneDeep vs Lodash clone vs Array.slice() vs. Object.assign()
Lodash cloneDeep vs. Lodash clone vs. Array.slice() vs. Array.slice(0) vs. Object.assign()
Lodash cloneDeep vs Lodash clone vs Array.splice() vs. Object.assign()
Lodash cloneDeep vs Lodash clone vs Array.splice() vs. Object.assign() vs Array.slice() vs Array.slice(0)
Object Clone Lodash vs structuredClone
Comments
Confirm delete:
Do you really want to delete benchmark?