Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
deep clone - lodash vs ramda vs structuredClone
(version: 0)
Comparing performance of:
lodash - cloneDeep vs structuredClone vs ramda - clone
Created:
3 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.21/lodash.min.js'></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.28.0/ramda.min.js"></script>
Script Preparation code:
var obj = { get stuff() { return "a string"; }, 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' }, arr: [{ a: 1, b: 'hello' }, { a: 2, b: 'world' }, ], s: new Set([1, 2, 3]), m: new Map([["a", 1], ["b", 2]]), }; var objCopy = null;
Tests:
lodash - cloneDeep
objCopy = _.cloneDeep(obj);
structuredClone
objCopy = structuredClone(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
structuredClone
ramda - 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
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what's being tested, compared, and the pros and cons of each approach. **What is being tested?** The test case measures the performance of three different methods to create a deep clone of an object: 1. `structuredClone` 2. `_` (Lodash) `cloneDeep` 3. `R.clone` (Ramda) These methods are used to copy an object, including its nested properties and arrays. **Options compared:** The benchmark compares the performance of these three methods on the same input object. * `structuredClone`: This is a new method introduced in ECMAScript 2020 that creates a deep clone of an object by serializing it to a Uint8Array and then deserializing it. * `_` (Lodash) `cloneDeep`: A popular JavaScript library function that recursively clones objects, arrays, and other data structures. * `R.clone` (Ramda): Another functional programming library that provides a way to create deep clones of objects. **Pros and cons:** Here's a brief summary of the pros and cons of each approach: * `structuredClone`: + Pros: It's a standard method introduced in ECMAScript 2020, making it a safe choice for future-proofing. + Cons: It may have performance implications due to serialization and deserialization. * `_` (Lodash) `cloneDeep`: + Pros: Widely used and well-maintained library with good performance. + Cons: It's not a standard method, which might make it harder to support in older browsers or environments. * `R.clone` (Ramda): + Pros: Part of the Ramda library, which is known for its functional programming approach and high performance. + Cons: May require additional setup due to the need for Ramda's ecosystem. **Library and syntax considerations:** * The benchmark uses the Lodash (`_`) and Ramda (`R`) libraries, which are popular choices in JavaScript development. These libraries provide a wide range of functions for data manipulation, filtering, sorting, and more. * No specific JavaScript features or syntax are used beyond what's standard in modern JavaScript. **Alternatives:** Other alternatives to these methods include: * `JSON.parse(JSON.stringify(obj))`: A simple method that works by serializing the object as JSON and then parsing it back into a JavaScript object. However, this can lead to unexpected behavior if the original object contains functions or other complex data structures. * `Object.assign(objCopy = {});`. This method creates an empty object (`objCopy`) and then uses `Object.assign()` to copy the properties from the original object (`obj`). This approach is simpler but might not work correctly with all types of objects. Keep in mind that these alternatives may have performance implications or limitations, especially when dealing with complex data structures.
Related benchmarks:
Deep object cloning with Lodash (cloneDeep vs merge vs assign)
Lodash cloneDeep vs freeze vs monokee deepClone
Lodash cloneDeep vs deepFreeze vs deepClone vs JSON.parse(JSON.stringify())
is lodash cloneDeep the BEST object deep cloner ? what about native structuredClone function ?
Lodash clone deep object array vs string array
Comments
Confirm delete:
Do you really want to delete benchmark?