Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
RFDC clone vs Lodash cloneDeep vs JSON Clone vs structuredClone
(version: 0)
Comparing performance of:
Lodash cloneDeep vs Json clone vs RFDC copy vs structuredClone
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" } ] } ]; 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);
structuredClone
myCopy = structuredClone(sampleObject);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Lodash cloneDeep
Json clone
RFDC copy
structuredClone
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
9 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
86015.6 Ops/sec
Json clone
262690.7 Ops/sec
RFDC copy
306364.3 Ops/sec
structuredClone
182697.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what is tested, compared, and their pros/cons. **Benchmark Definition** The benchmark compares the performance of four different methods to create a deep copy of an object: 1. `Lodash cloneDeep` 2. `JSON Clone` (a built-in JavaScript function) 3. `structuredClone` (a new API introduced in ECMAScript 2020) 4. `RFDC copy` (an external library, Rfdc) **Comparison** The benchmark prepares a sample object with nested structures and then creates a deep copy of it using each of the four methods. The test case names are included to provide context. Here's a brief overview of each method: 1. **Lodash cloneDeep**: Lodash is a popular JavaScript utility library that provides various helper functions, including `cloneDeep` for creating deep copies of objects. 2. **JSON Clone**: This is a built-in JavaScript function that creates a shallow copy of an object using the JSON.parse(JSON.stringify()) syntax. 3. **structuredClone**: This is a new API introduced in ECMAScript 2020 that allows creating a deep copy of an object without serializing and deserializing it, which can be slower for very large objects. 4. **RFDC copy**: Rfdc is an external library that provides a high-performance way to create deep copies of objects. **Pros and Cons** Here's a brief summary of the pros and cons of each method: 1. **Lodash cloneDeep**: * Pros: Fast, widely supported, and easy to use. * Cons: Requires including Lodash as a dependency. 2. **JSON Clone**: * Pros: Built-in function, no dependencies required. * Cons: Can be slower than other methods due to serialization and deserialization. 3. **structuredClone**: * Pros: Supports deep copies without serialization, efficient for large objects. * Cons: New API, may not be supported by older browsers or Node.js versions. 4. **RFDC copy**: * Pros: High-performance, optimized for deep copying. * Cons: External library dependency, may not be widely supported. **Benchmark Results** The latest benchmark results show the execution speed of each method in seconds per second (ExecutionsPerSecond). The fastest method will have the highest value. In this case, `RFDC copy` is the fastest, followed by `Lodash cloneDeep`, then `structuredClone`, and finally `JSON Clone`. Keep in mind that these results may vary depending on your specific use case, object size, and browser/node.js version. In conclusion, the choice of method depends on your priorities: * If you need a fast and widely supported solution, Lodash cloneDeep or RFDC copy might be the best choice. * If you're targeting older browsers or Node.js versions that don't support structuredClone, JSON Clone might still be an option. * For high-performance deep copying without serialization, structuredClone is worth considering.
Related benchmarks:
RFDC clone vs Lodash cloneDeep vs JSON Clone
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
Comments
Confirm delete:
Do you really want to delete benchmark?