Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
RFDC clone vs Lodash cloneDeep vs JSON Parse 123
(version: 0)
Comparing performance of:
Lodash cloneDeep vs Json clone vs RFDC copy
Created:
4 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" } ] } ]; 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:
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):
**Benchmark Explanation** The provided benchmark measures the performance of three different methods for creating a deep copy of an object in JavaScript: 1. **RFDC (Recursive Function Call Dictionary) copy**: This method uses a recursive function to create a new object and then copies the properties from the original object to the new one. 2. **Lodash cloneDeep**: This method uses the `cloneDeep` function from the Lodash library, which is a popular utility library for JavaScript. 3. **JSON Parse**: This method uses the `JSON.parse()` function with `JSON.stringify()` to create a deep copy of the object. **Options Compared** The three methods are compared in terms of their performance and execution time. **Pros and Cons** * **RFDC copy**: + Pros: Simple implementation, can be optimized for small objects. + Cons: Can be slow for large objects due to recursive function calls. * **Lodash cloneDeep**: + Pros: Optimized for deep copying, handles complex object graphs well. + Cons: Requires the Lodash library, which adds extra overhead. * **JSON Parse**: + Pros: Fast and efficient, uses built-in JavaScript functions. + Cons: Can only handle objects with primitive values in their properties. **Library Usage** The `cloneDeep` function from Lodash is used to create a deep copy of the object. This library provides optimized implementations for common functional programming tasks, including array and object manipulation. **Special JS Features/Syntax** None mentioned in this benchmark. **Other Considerations** * The benchmark uses Chrome 92 as the testing browser, which may not be representative of all users. * The benchmark results are averaged over multiple executions per second, which can affect the accuracy of the results. **Alternatives** If you're looking for alternative deep copying methods, consider: * **Object.assign()**: A built-in JavaScript method that creates a shallow copy of an object. * **Array.prototype.slice()**: Can be used to create a shallow copy of an array or object with primitive values in its properties. * **lodash.clone()**: Another Lodash function that creates a deep copy of an object, but without the `cloneDeep` function's optimization for complex object graphs.
Related benchmarks:
RFDC clone vs Lodash cloneDeep vs JSON Clone
RFDC clone vs Lodash cloneDeep vs JSON Parse
RFDC clone vs Lodash clone vs JSON Clone
RFDC clone (circles: true) vs Lodash cloneDeep vs JSON Clone
Object Cloning Comparsion
Comments
Confirm delete:
Do you really want to delete benchmark?