Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash cloneDeep vs JSON Clone vs Ramda Clone vs rfdc
(version: 0)
Comparing performance of:
Lodash cloneDeep vs Json clone vs Ramda clone vs rfdc clone
Created:
5 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://cdn.jsdelivr.net/npm/rfdc@1.1.4/index.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);
rfdc clone
myCopy = rfdc(MyObject);
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
rfdc clone
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
5 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:145.0) Gecko/20100101 Firefox/145.0
Browser/OS:
Firefox 145 on Mac OS X 10.15
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash cloneDeep
1505276.0 Ops/sec
Json clone
1328058.8 Ops/sec
Ramda clone
3187524.2 Ops/sec
rfdc clone
107300160.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON benchmark and explain what's being tested. **Benchmark Definition** The benchmark is designed to compare the performance of four different methods for creating a deep copy of an object: Lodash's `cloneDeep`, JSON's `parse` and `stringify` methods, Ramda's `clone`, and rfdc (a library specifically designed for deep cloning). **Script Preparation Code** The script preparation code creates an object `MyObject` with nested properties, including a string that explains the purpose of the benchmark. The script also initializes an empty variable `myCopy` to be used as the destination for the cloned objects. **Html Preparation Code** The HTML preparation code includes links to external libraries: * Lodash (version 4.17.5) * Ramda (version 0.25.0) * rfdc (version 1.1.4) These libraries are used to implement the different cloning methods being compared in the benchmark. **Individual Test Cases** Each test case defines a single benchmark definition, which is the actual code that creates a deep copy of `MyObject`. The test cases are: * Lodash cloneDeep: `myCopy = _.cloneDeep(MyObject);` * Json clone: `myCopy = JSON.parse(JSON.stringify(MyObject));` * Ramda clone: `myCopy = R.clone(MyObject);` * rfdc clone: `myCopy = rfdc(MyObject);` **Pros and Cons of Each Approach** Here's a brief summary of the pros and cons of each approach: * **Lodash cloneDeep**: Pros: + Robust implementation with many features (e.g., support for arrays, maps). + Well-documented. * Cons: + Larger overhead due to its feature-rich implementation. * **JSON parse and stringify**: Pros: + Simple and lightweight implementation. + Wide adoption and compatibility. * Cons: + Not designed specifically for deep cloning, which can lead to issues with circular references or non-serializable objects. + May not perform well on large datasets. * **Ramda clone**: Pros: + Elegant and concise implementation. + Well-documented. * Cons: + Smaller community support compared to Lodash. * **rfdc**: Pros: + Optimized for deep cloning, with features like handling circular references and non-serializable objects. + Lightweight and efficient. **Other Considerations** When choosing a method for creating a deep copy of an object, consider the following factors: * **Performance**: If performance is critical, you may want to opt for rfdc or Ramda clone. Lodash cloneDeep has a larger overhead due to its feature-rich implementation. * **Feature set**: If your use case requires specific features (e.g., support for arrays, maps), you may prefer Lodash cloneDeep. * **Readability and maintainability**: Ramda clone is known for its elegant and concise implementation. **Alternatives** Other alternatives for deep cloning in JavaScript include: * `Object.assign()`: While not designed specifically for deep cloning, `Object.assign()` can be used to create a shallow copy of an object. However, it may not work as expected with deeply nested objects. * **Array.prototype.slice()`: Similar to `Object.assign()`, `Array.prototype.slice()` can be used to create a shallow copy of an array. Keep in mind that these alternatives may not offer the same level of performance or feature set as the methods being compared in the benchmark.
Related benchmarks:
Lodash cloneDeep vs JSON Clone vs Ramda Clone
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?