Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
RFDC clone vs Lodash cloneDeep vs JSON Clone vs Clone
(version: 0)
Comparing performance of:
Lodash cloneDeep vs Json clone vs RFDC copy vs Clone
Created:
2 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/clone@2.1.2/clone.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);
Clone
myCopy = clone(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
Clone
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36
Browser/OS:
Chrome 123 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash cloneDeep
53075.7 Ops/sec
Json clone
91598.8 Ops/sec
RFDC copy
255535.5 Ops/sec
Clone
52732.7 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down what's being tested in the provided benchmark. **Benchmark Description** The benchmark compares the performance of four different cloning methods: 1. `RFDC` (Randomized Deep Clone): A custom implementation for cloning complex objects. 2. `Lodash cloneDeep`: The `cloneDeep` function from the popular Lodash library, which is designed to create deep copies of objects. 3. `JSON.parse(JSON.stringify())`: A built-in JavaScript method for cloning objects by serializing and deserializing them as JSON strings. 4. A custom implementation labeled "Clone". **Options Compared** The four cloning methods are being compared in terms of their performance, specifically: * Execution frequency per second (i.e., how many times each method can be executed within a second) * Raw UA string (a unique identifier for the browser and device) **Pros and Cons of Each Approach** 1. **RFDC**: Pros: Custom implementation, potentially optimized for specific use cases; Cons: May introduce additional overhead due to its custom nature. 2. **Lodash cloneDeep**: Pros: Well-tested and widely used library; Cons: Adds an external dependency (Lodash) and may have some limitations in terms of performance or compatibility. 3. **JSON.parse(JSON.stringify())**: Pros: Built-in method, easy to implement; Cons: May not work well with complex objects or circular references, as it only serializes the object's values, not its references. 4. **Clone** (custom implementation): Pros: Custom optimization for specific use cases; Cons: Lack of testing and validation, potentially introducing errors or performance issues. **Individual Test Cases** Each test case executes a different cloning method on the `sampleObject` array: 1. `Lodash cloneDeep`: Uses `_.cloneDeep` to create a deep copy of the object. 2. `JSON.parse(JSON.stringify())`: Serializes the object as JSON, then deserializes it back into an object. 3. `RFDC copy`: Calls the `rfdc()` function with `sampleObject` as an argument, which is expected to return a deep clone of the object. 4. `Clone`: Implements a custom cloning method using the same logic as `RFDC`. **Benchmark Results** The latest benchmark results show the execution frequency per second for each test case: 1. `RFDC copy`: 255535.515625 executions/second 2. `Json clone`: 91598.765625 executions/second 3. `Lodash cloneDeep`: 53075.73046875 executions/second 4. `Clone`: 52732.72265625 executions/second The results suggest that the custom `RFDC` implementation performs better than Lodash's `cloneDeep`, while `JSON.parse(JSON.stringify())` is significantly slower due to its limitations. The custom "Clone" implementation falls in between, but its performance is not as good as `RFDC`.
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
RFDC clone vs Clone vs JSON Clone
Comments
Confirm delete:
Do you really want to delete benchmark?