Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash cloneDeep vs JSON Clone vs Ramda Clone vs Pvorb Clone Corrected
(version: 0)
Comparing performance of:
Lodash cloneDeep vs Json clone vs Ramda clone vs Pvorb Clone
Created:
6 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 src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/clone/2.1.2/clone.min.js"></script>
Script Preparation code:
var MyObject = { 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...' } }; var myCopy = null;
Tests:
Lodash cloneDeep
myCopy = _.cloneDeep(MyObject);
Json clone
myCopy = JSON.parse(JSON.stringify(MyObject));
Ramda clone
myCopy = R.clone(MyObject);
Pvorb Clone
myCopy = clone(MyObject, false);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Lodash cloneDeep
Json clone
Ramda clone
Pvorb Clone
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
gemma2:9b
, generated one year ago):
This benchmark compares the performance of four different methods for creating deep copies of JavaScript objects: * **Lodash `cloneDeep`:** A function from the Lodash library that creates a deep copy of an object, preserving all nested properties and values. * **JSON Clone (`JSON.parse(JSON.stringify(MyObject))`) :** This approach serializes the original object into a JSON string using `JSON.stringify()`, then parses it back into a new object using `JSON.parse()`. This effectively creates a shallow copy, but since objects are copied recursively, it results in a deep copy. * **Ramda `clone`:** A function from the Ramda library that creates a deep copy of an object. * **Pvorb Clone (`clone(MyObject, false)`) :** A function from the clone library that creates a deep copy of an object. **Pros and Cons:** * **Lodash `cloneDeep`**: * **Pros:** Well-established and widely used, generally performs well. * **Cons:** Adds dependency on Lodash library. * **JSON Clone:** * **Pros:** Built into JavaScript, no additional dependencies needed. * **Cons:** Can be slightly slower than dedicated libraries due to the stringification/parsing overhead. * **Ramda `clone`**: * **Pros:** Part of a functional programming library, potentially efficient for large complex objects. * **Cons:** Adds dependency on Ramda library. * **Pvorb Clone:** * **Pros:** Focused solely on cloning, might be optimized for performance. * **Cons:** Less widely known than Lodash or Ramda, smaller community support. **Considerations:** The best choice depends on your specific needs: * **Library familiarity:** If you're already using Lodash or Ramda, their `clone` functions are convenient. * **Performance:** Benchmarking (like this one!) is essential to determine the fastest option for your use case. * **Complexity of objects:** For very complex nested objects, functional libraries like Ramda might offer advantages. **Alternatives:** There are other JavaScript cloning libraries and techniques available, such as: * **Underscore.js**: Similar to Lodash. * **Custom recursive functions**: You can write your own function to recursively copy object properties. Remember that the performance of cloning can vary based on factors like object size, complexity, and your specific environment.
Related benchmarks:
Lodash cloneDeep vs JSON Clone vs Ramda Clone vs Pvorb Clone - Fixed
Lodash cloneDeep vs JSON Clone vs Ramda Clone test
Lodash cloneDeep vs JSON Clone vs Ramda Clone vs Pvorb Clonesdsd
Lodash cloneDeep vs JSON Clone vs Ramda Clone vs Pvorb Cloneaaaaaaaaaaaaaaaaaaaaaaaaaa
Comments
Confirm delete:
Do you really want to delete benchmark?