Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash cloneDeep vs JSON Clone vs Ramda Clone
(version: 0)
Comparing performance of:
Lodash cloneDeep vs Json clone vs Ramda clone
Created:
7 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 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);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Lodash cloneDeep
Json clone
Ramda clone
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/130.0.0.0 Safari/537.36
Browser/OS:
Chrome 130 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash cloneDeep
1240042.9 Ops/sec
Json clone
976928.9 Ops/sec
Ramda clone
2030436.5 Ops/sec
Autogenerated LLM Summary
(model
gemma2:9b
, generated one year ago):
This benchmark tests the performance of three different ways to create a deep copy of an object in JavaScript: * **Lodash `cloneDeep`:** Lodash is a popular library that provides utility functions for working with JavaScript objects and arrays. Its `cloneDeep` function creates a completely independent copy of an object, including nested objects and arrays. * **JSON Clone:** This approach uses the built-in `JSON.stringify()` and `JSON.parse()` methods to convert the object into a JSON string and then back into an object. While simple, it might not be the most efficient method for large or complex objects. * **Ramda `clone`:** Ramda is another functional programming library that offers various functions for working with data. Its `clone` function creates a deep copy of an object in a similar way to Lodash's `cloneDeep`. **Pros and Cons:** * **Lodash `cloneDeep`:** * **Pros:** Well-established, reliable, efficient for most use cases. * **Cons:** Adds a dependency on the Lodash library. * **JSON Clone:** * **Pros:** No external dependencies, readily available in standard JavaScript. * **Cons:** Can be slower than dedicated deep copying libraries, especially for large objects. * **Ramda `clone`:** * **Pros:** Functional programming paradigm, potentially more concise code, efficient. * **Cons:** Adds a dependency on the Ramda library. Requires familiarity with functional programming concepts. **Other Considerations:** The choice of method depends on your specific needs: * **Object Size and Complexity:** For very large or complex objects, dedicated libraries like Lodash or Ramda are likely to perform better than JSON cloning. * **Performance Requirements:** If performance is critical, benchmark different approaches with your specific data to determine the most efficient option. * **Code Maintainability:** Consider the readability and maintainability of your code when choosing a method. **Alternatives:** There are other JavaScript libraries that provide deep copying functionality, such as: * **Underscore.js:** Similar to Lodash but might offer different performance characteristics. * **Immer:** Offers an "immersive" approach to object manipulation, potentially improving performance for frequent updates. Let me know if you have any more questions!
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
Lodash cloneDeep vs JSON Clone vs Ramda Clone vs Pvorb Clone Corrected
Comments
Confirm delete:
Do you really want to delete benchmark?