Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
klona vs RFDC clone vs Lodash cloneDeep vs JSON Clone
(version: 0)
Comparing performance of:
Lodash cloneDeep vs Json clone vs RFDC copy vs klona copy
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/rfdc@1.3.0/index.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"></script> <script src="https://unpkg.com/klona@2.0.4/json/index.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);
klona copy
myCopy = klona(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
klona copy
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
3 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:147.0) Gecko/20100101 Firefox/147.0
Browser/OS:
Firefox 147 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash cloneDeep
71006.6 Ops/sec
Json clone
226446.3 Ops/sec
RFDC copy
348549.5 Ops/sec
klona copy
856155.1 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the benchmark and explain what's being tested. The benchmark is comparing four different approaches to create a deep copy of an object in JavaScript: 1. **Lodash `cloneDeep`**: This function creates a deep copy of an object by recursively traversing the object's properties and creating new objects for each nested property. 2. **JSON cloning**: This approach uses the `JSON.parse(JSON.stringify(obj))` method to create a deep copy of an object. However, this method can fail if the object contains functions or other non-enumerable properties. 3. **RFDC (Recursive Functionally Derived Clone) copy**: This function creates a deep copy of an object by recursively traversing the object's properties and creating new objects for each nested property, similar to Lodash `cloneDeep`. However, RFDC has some performance optimizations that make it faster than Lodash in certain cases. 4. **Klona copy**: Klona is a lightweight library specifically designed for cloning JavaScript objects. It uses a combination of recursion and caching to create fast and efficient deep copies. Now, let's discuss the pros and cons of each approach: * **Lodash `cloneDeep`**: + Pros: Robustness, ease of use, and well-maintained. + Cons: Can be slower than RFDC due to additional overhead from Lodash's internal mechanisms. * **JSON cloning**: + Pros: Simple and easy to implement. + Cons: Can fail if the object contains functions or other non-enumerable properties, and can be slow for large objects. * **RFDC copy**: + Pros: Fast performance, optimized for certain use cases. + Cons: Less robust than Lodash `cloneDeep`, and its internal mechanics might not be as well-understood. * **Klona copy**: + Pros: Lightweight, fast, and optimized for cloning JavaScript objects. + Cons: Might require additional setup or configuration to work correctly in certain environments. In the latest benchmark results, we can see that: * Klona copy outperforms RFDC copy by a significant margin. * Lodash `cloneDeep` is slower than RFDC copy but still performs well compared to JSON cloning. * JSON cloning fails to create a deep copy due to its limitations. Overall, the choice of approach depends on the specific use case and performance requirements. If you need a robust and easy-to-use solution, Lodash `cloneDeep` might be a good choice. However, if you're looking for a lightweight and optimized solution, Klona copy or RFDC copy could be a better fit.
Related benchmarks:
RFDC clone vs Lodash cloneDeep vs JSON Clone
RFDC clone vs Lodash clone vs JSON Clone
klona vs Lodash cloneDeep
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?