Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash cloneDeep vs JSON Clone vs Ramda Clone test 2019Nov22
(version: 0)
Comparing performance of:
Lodash cloneDeep vs Json clone vs Ramda 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.15/lodash.min.js'></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.26.1/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:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
Browser/OS:
Chrome 122 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash cloneDeep
802245.5 Ops/sec
Json clone
626660.2 Ops/sec
Ramda clone
1158839.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Overview** MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks. The provided benchmark compares the performance of three different methods for cloning complex objects: `_.cloneDeep` from Lodash, `JSON.parse(JSON.stringify())`, and `R.clone()` from Ramda. **Tested Options** The benchmark tests three options: 1. **Lodash cloneDeep**: This method uses the `_` object from Lodash to create a deep copy of the input object. 2. **JSON Clone**: This method uses the `JSON.parse(JSON.stringify())` function to convert the input object to a JSON string and then parse it back into an object, effectively cloning the original object. 3. **Ramda clone**: This method uses the `R.clone()` function from Ramda to create a deep copy of the input object. **Pros and Cons** Here's a brief summary of the pros and cons of each approach: * **Lodash cloneDeep**: + Pros: High performance, easy to use, and well-maintained. + Cons: Requires an additional dependency (Lodash) and may not be suitable for very large objects due to memory limitations. * **JSON Clone**: + Pros: Lightweight, easy to implement, and works on most platforms. + Cons: Slow performance compared to Lodash cloneDeep, as it involves converting the object to a string and parsing it back into an object. * **Ramda clone**: + Pros: Similar performance to Lodash cloneDeep, with the added benefit of being part of the Ramda library (which provides additional functional programming utilities). + Cons: Requires an additional dependency (Ramda) and may have higher memory usage compared to Lodash cloneDeep due to its object-oriented approach. **Library Usage** In this benchmark, Lodash and Ramda are used as external libraries. These libraries provide functions that can be used to perform specific tasks, such as deep cloning objects. The `JSON.parse(JSON.stringify())` function is a built-in JavaScript method that performs a similar task without the need for an external library. **Special JS Features** This benchmark does not use any special JavaScript features or syntax. It relies on standard JavaScript methods and libraries (Lodash, Ramda) to perform the cloning operations. **Alternative Approaches** Other approaches to deep cloning objects include: * Using `Object.assign()` with a custom object creation function: `const clone = Object.create(null); // Create an empty object; const myCopy = Object.assign(clone, MyObject);` * Using `Array.prototype.slice()` and `JSON.parse(JSON.stringify())`: `const clone = JSON.parse(JSON.stringify(MyObject));` (although this approach has similar performance issues to the JSON Clone method) * Implementing a custom cloning function using recursion or iteration: These approaches can be more memory-efficient but may also introduce additional complexity and performance overhead. Note that these alternative approaches may not provide the same level of performance as Lodash cloneDeep or Ramda clone, especially for large objects.
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?