Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
RFDC clone (circles: true) vs Lodash cloneDeep (+ cycle)
(version: 0)
Comparing performance of:
Lodash cloneDeep vs RFDC copy
Created:
3 years ago
by:
Guest
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" } ] } ]; sampleObject[0].cycle = sampleObject[0] var myCopy = null;
Tests:
Lodash cloneDeep
myCopy = _.cloneDeep(sampleObject);
RFDC copy
var clone = rfdc({ circles: true }); myCopy = clone(sampleObject);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash cloneDeep
RFDC copy
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Browser/OS:
Chrome 124 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash cloneDeep
106465.0 Ops/sec
RFDC copy
528269.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks! **Benchmark Overview** The provided benchmark measures the performance difference between two approaches to cloning an object: Lodash's `cloneDeep` and the RFDC (Randomized Fast Deep Clone) algorithm. **RFDC Algorithm** RFDC is a JavaScript implementation that uses recursion and caching to create deep copies of objects. It's designed to be fast and efficient while also handling complex data structures like arrays and objects with nested properties. In this benchmark, the RFDC algorithm creates a copy of the `sampleObject` array using the `var clone = rfdc({ circles: true });\r\nmyCopy = clone(sampleObject);` line. The `circles` option is set to `true`, which likely affects the cloning behavior. **Lodash's `cloneDeep`** Lodash's `cloneDeep` function creates a deep copy of an object using a recursive approach that handles complex data structures like arrays and objects with nested properties. In this benchmark, the Lodash `cloneDeep` function is used to create a copy of the `sampleObject` array using the `myCopy = _.cloneDeep(sampleObject);` line. **Comparison** The benchmark compares the execution times of both approaches on a desktop device running Chrome 124. The results show that: * RFDC copy takes around 528,269 executions per second * Lodash cloneDeep takes around 106,465 executions per second This suggests that RFDC is significantly faster than Lodash's `cloneDeep` for this particular use case. **Pros and Cons** **RFDC Algorithm:** Pros: * Fast execution times * Handles complex data structures like arrays and objects with nested properties * May be more efficient for large datasets Cons: * Can be less intuitive to use compared to other cloning algorithms * May not provide the same level of debuggability as other approaches **Lodash's `cloneDeep`** Pros: * Widely used and well-maintained library * Provides a consistent and reliable way to clone objects * Easy to understand and use for most developers Cons: * May be slower than RFDC for large datasets * Can handle only a certain level of complexity before becoming slow **Other Considerations** When choosing between these two approaches, consider the following factors: * Performance: If you need fast execution times, RFDC might be the better choice. If you prioritize ease of use and reliability, Lodash's `cloneDeep` might be a better fit. * Complexity: If your dataset is relatively simple, Lodash's `cloneDeep` might suffice. For more complex data structures, RFDC or other custom cloning algorithms might be necessary. **Skip Preambles?** Take a deep breath... I think we've covered the essential points about this JavaScript microbenchmark!
Related benchmarks:
RFDC clone vs Lodash clone vs JSON Clone
RFDC clone vs clone-deep clone vs Lodash cloneDeep vs JSON Clone
RFDC clone vs Lodash cloneDeep vs JSON Clone vs structured clone
RFDC clone (circles: true) vs Lodash cloneDeep vs JSON Clone
Comments
Confirm delete:
Do you really want to delete benchmark?