Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
deep clone - lodash vs ramda vs json
(version: 0)
Comparing performance of:
lodash - cloneDeep vs json - parse/stringify vs ramda - clone
Created:
7 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 src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script>
Script Preparation code:
var obj = { author: 'Jason Carmona', fieldNumber: 112050642, nestedObject: { funFact1: 'You burn more calories sleeping than you do watching television', funFact2: 'The average person spends 6 months of their lifetime waiting on a red light to turn green', funFact3: 'There are more possible iterations of a game of chess than there are atoms in the known universe', funFact4: 'Coca-Cola would be green if coloring wasn’t added to it', funFact5: 'You cannot snore and dream at the same time' } }; var objCopy = null;
Tests:
lodash - cloneDeep
objCopy = _.cloneDeep(obj);
json - parse/stringify
objCopy = JSON.parse(JSON.stringify(obj));
ramda - clone
objCopy = R.clone(obj);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
lodash - cloneDeep
json - parse/stringify
ramda - clone
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
6 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36
Browser/OS:
Chrome 140 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash - cloneDeep
1335517.5 Ops/sec
json - parse/stringify
950173.2 Ops/sec
ramda - clone
2305887.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark JSON and explain what's being tested, compared, and the pros/cons of different approaches. **Benchmark Definition:** The benchmark compares three ways to create a deep clone of an object: 1. **Lodash**: `_._cloneDeep(obj)` 2. **JSON**: `JSON.parse(JSON.stringify(obj))` 3. **Ramda**: `R.clone(obj)` **Libraries and their purposes:** * **Lodash**: A popular utility library for JavaScript that provides a wide range of functions for tasks such as array manipulation, string manipulation, and object manipulation. * **Ramda**: A functional programming library for JavaScript that provides a set of higher-order functions to manipulate data. **Comparison options:** The benchmark compares the execution time of each approach: 1. **Lodash - cloneDeep**: Uses Lodash's `cloneDeep` function to create a deep clone of the object. 2. **JSON - parse/stringify**: Uses the `JSON.parse(JSON.stringify(obj))` method to create a deep clone of the object by stringifying and parsing the original object. 3. **Ramda - clone**: Uses Ramda's `R.clone` function to create a deep clone of the object. **Pros and cons:** * **Lodash - cloneDeep**: + Pros: - Efficient and well-tested implementation - Supports complex data structures like nested objects + Cons: - Requires an additional library (Lodash) - May have a higher memory footprint due to the use of a separate function call * **JSON - parse/stringify**: + Pros: - Lightweight and easy to implement - Does not require an additional library + Cons: - Can be slower for large objects due to the stringification and parsing process - May not support all types of data (e.g., circular references) * **Ramda - clone**: + Pros: - Compact and concise implementation - Supports functional programming concepts like immutability + Cons: - Requires an additional library (Ramda) - May have a higher memory footprint due to the use of a separate function call **Special considerations:** * None mentioned in this benchmark. **Other alternatives:** * For creating deep clones, other libraries like **Immer.js**, **Mycelium**, or **deep-clone** can also be used. * For lightweight and efficient cloning, **JSON.parse(JSON.stringify(obj))` alone can be used, but with caution for large objects and circular references. The benchmark result shows the execution time of each approach on a Mac OS X 10.15.7 desktop environment with Chrome 121 browser. The Ramda implementation performs best, followed by Lodash, and then JSON. However, it's essential to consider the trade-offs between performance, memory usage, and library dependencies when choosing an approach for your specific use case.
Related benchmarks:
Deep Clone Performance - JSON vs Lodash vs Ramda vs Native
Lodash deep clone vs JSON.stringfy
Lodash deeper clone vs Spread Clone
Deep clone: lodash vs ramda
Lodash cloneDeep vs JSON Clone vs freeze and get - access a value
Comments
Confirm delete:
Do you really want to delete benchmark?