Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
RFDC clone vs Lodash cloneDeep vs JSON Clone vs structured clone
(version: 0)
Comparing performance of:
Lodash cloneDeep vs Json clone vs RFDC copy vs structured clone
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 src="https://cdn.jsdelivr.net/npm/@ungap/structured-clone@1.0.1/cjs/index.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);
structured clone
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
structured clone
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one month ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36
Browser/OS:
Chrome 142 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash cloneDeep
119054.3 Ops/sec
Json clone
292131.9 Ops/sec
RFDC copy
698844.2 Ops/sec
structured clone
148502.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
The provided benchmark measures the performance of different methods for cloning a nested JavaScript object. The test cases use various libraries and techniques to create copies of the input object, which is a complex JSON data structure. Here's a breakdown of each test case: 1. **Lodash cloneDeep**: This method uses Lodash's `cloneDeep` function to create a deep copy of the input object. Lodash is a popular JavaScript utility library that provides various functions for tasks such as array manipulation, string manipulation, and more. In this context, `cloneDeep` creates a new object with the same structure and values as the original object. 2. **JSON Clone**: This method uses the built-in `JSON.parse(JSON.stringify(obj))` syntax to create a deep copy of the input object. This syntax serializes the object to a JSON string, then parses it back into an object, effectively creating a new object with the same structure and values as the original. 3. **RFDC Copy**: This method uses the RFDC (Recursive Function for Deep Cloning) library's `rfdc()` function to create a deep copy of the input object. RFDC is a lightweight library specifically designed for deep cloning JavaScript objects. 4. **Structured Clone**: This method uses the structured clone algorithm from the WebAssembly specification to create a deep copy of the input object. Structured clones are a way to serialize and deserialize complex data structures, including nested objects. In summary, each test case creates a new object using a different technique: * Lodash cloneDeep: Uses a dedicated library function * JSON Clone: Uses built-in JavaScript syntax * RFDC Copy: Uses a lightweight library function * Structured Clone: Uses the WebAssembly specification's algorithm The benchmark measures the performance of these methods by executing each test case multiple times and reporting the average execution time per second. When comparing these results, we can see that: * Lodash cloneDeep is slightly faster than JSON Clone and RFDC Copy * JSON Clone is slower than Structured Clone * RFDC Copy is likely faster than JSON Clone due to its lightweight nature However, it's essential to note that performance differences may vary depending on the specific use case, input data size, and other factors. These results should be interpreted with caution and may not reflect your own experience or requirements. If you're interested in understanding the underlying implementation details of each method, I can provide more information on Lodash cloneDeep, RFDC Copy, and Structured Clone.
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 vs clone-deep clone vs Lodash cloneDeep vs JSON Clone
Comments
Confirm delete:
Do you really want to delete benchmark?