Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
RFDC clone vs Lodash cloneDeep vs JSON Clone
(version: 1)
Comparing performance of:
Lodash cloneDeep vs Json clone vs RFDC copy
Created:
5 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/rfdc@1.1.4/index.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/lodash@4.17.20/lodash.min.js"></script>
Script Preparation code:
var sampleObject = [{ "id": "0001", "type": "donut", "name": "Cake", "ppu": 0.55, "batters": { "batter": [{ "id": "1001", "type": "Regular" }, { "id": "1002", "type": "Chocolate" }, { "id": "1003", "type": "Blueberry" }, { "id": "1004", "type": "Devil's Food" } ] }, "topping": [{ "id": "5001", "type": "None" }, { "id": "5002", "type": "Glazed" }, { "id": "5005", "type": "Sugar" }, { "id": "5007", "type": "Powdered Sugar" }, { "id": "5006", "type": "Chocolate with Sprinkles" }, { "id": "5003", "type": "Chocolate" }, { "id": "5004", "type": "Maple" } ] }, { "id": "0002", "type": "donut", "name": "Raised", "ppu": 0.55, "batters": { "batter": [{ "id": "1001", "type": "Regular" }] }, "topping": [{ "id": "5001", "type": "None" }, { "id": "5002", "type": "Glazed" }, { "id": "5005", "type": "Sugar" }, { "id": "5003", "type": "Chocolate" }, { "id": "5004", "type": "Maple" } ] }, { "id": "0003", "type": "donut", "name": "Old Fashioned", "ppu": 0.55, "batters": { "batter": [{ "id": "1001", "type": "Regular" }, { "id": "1002", "type": "Chocolate" } ] }, "topping": [{ "id": "5001", "type": "None" }, { "id": "5002", "type": "Glazed" }, { "id": "5003", "type": "Chocolate" }, { "id": "5004", "type": "Maple" } ] } ]; var myCopy = null;
Tests:
Lodash cloneDeep
myCopy = _.cloneDeep(sampleObject);
Json clone
myCopy = JSON.parse(JSON.stringify(sampleObject));
RFDC copy
var clone = rfdc(); myCopy = clone(sampleObject);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Lodash cloneDeep
Json clone
RFDC copy
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
10 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0
Browser/OS:
Firefox 140 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash cloneDeep
43986.3 Ops/sec
Json clone
149650.9 Ops/sec
RFDC copy
163210.7 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested, compared, and their pros and cons. **Benchmark Definition:** The benchmark is testing the performance of three different methods to create a deep copy of an object: 1. `Lodash cloneDeep` 2. `JSON Clone` 3. `RFDC copy` (from the `rfdc` library) **Object Structure:** The test object `sampleObject` contains multiple nested objects, including arrays and complex data structures. **Comparison:** The three methods are compared in terms of their execution speed, measured by the number of executions per second. **Options Compared:** 1. **Lodash cloneDeep**: A popular JavaScript library that provides a deep cloning function. 2. **JSON Clone**: A simple method to create a deep copy of an object using JSON parsing and stringification. 3. **RFDC copy**: A custom implementation from the `rfdc` library, which is optimized for performance. **Pros and Cons:** 1. **Lodash cloneDeep**: * Pros: Robust and widely used, well-maintained, and supports various data types. * Cons: Requires an additional dependency (the Lodash library), can be overkill for simple cloning tasks. 2. **JSON Clone**: * Pros: Lightweight, easy to understand, and no dependencies required. * Cons: May not work correctly with complex data structures or nested objects, and can lead to slower performance due to the parsing and stringification process. 3. **RFDC copy**: * Pros: Optimized for performance, supports complex data structures, and doesn't require additional libraries. * Cons: Custom implementation, may have a steeper learning curve, and not as widely used as other cloning methods. **Other Considerations:** * The `rfdc` library is optimized for performance and provides a custom implementation of the cloning algorithm. However, its documentation and community support are limited compared to Lodash. * JSON Clone is a simple approach that may work well for small cloning tasks but can become cumbersome for more complex data structures. **Benchmark Results:** The latest benchmark results show that: 1. **RFDC copy**: Has the highest execution speed (256994 executions per second). 2. **JSON Clone**: Falls behind with an average execution speed of 120,000 executions per second. 3. **Lodash cloneDeep**: Has a moderate execution speed, slightly above JSON Clone's average. These results suggest that `RFDC copy` is the most efficient way to create a deep copy of the test object, followed by Lodash cloneDeep, and then JSON Clone. However, it's essential to consider the specific requirements and constraints of your project when choosing a cloning method.
Related benchmarks:
RFDC clone vs Lodash cloneDeep vs JSON Parse
RFDC clone vs Lodash clone vs JSON Clone
RFDC clone vs clone-deep clone vs Lodash cloneDeep vs JSON Clone
RFDC clone (circles: true) vs Lodash cloneDeep vs JSON Clone
Comments
Confirm delete:
Do you really want to delete benchmark?