Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
RFDC clone vs lodash cloneDeep vs JSON Clone vs 递归 vs klona
(version: 1)
比较 rfdc 深度拷贝与 cloneDeep 与 json clone 与递归 的速度
Comparing performance of:
myCopy = _.cloneDeep(sampleObject); vs JSON Clone vs RFDC 深度拷贝 vs 递归 vs klona test
Created:
3 years ago
by:
Registered User
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://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:
myCopy = _.cloneDeep(sampleObject);
myCopy = _.cloneDeep(sampleObject);
JSON Clone
myCopy = JSON.parse(JSON.stringify(sampleObject));
RFDC 深度拷贝
var clone = rfdc({ proto: false,circles: false }); myCopy = clone(sampleObject);
递归
function deepCopy(data) { const t = typeof(data); let o; if (t === 'array') { o = []; } else if (t === 'object') { o = {}; } else { return data; } if (t === 'array') { for (let i = 0; i < data.length; i++) { o.push(deepCopy(data[i])); } } else if (t === 'object') { for (const i in data) { if (!data.hasOwnProperty(i)) { continue; } o[i] = deepCopy(data[i]); } } return o; } myCopy = deepCopy(sampleObject)
klona test
myCopy = klona(sampleObject);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
myCopy = _.cloneDeep(sampleObject);
JSON Clone
RFDC 深度拷贝
递归
klona test
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):
It seems like you're providing a detailed report on benchmarking different cloning techniques for objects in JavaScript. To summarize, here are the results: 1. `klona` (a lightweight object clone library) performs best with an execution rate of 577549.6875 executions per second. 2. Recursive deep copy (`deepCopy`) is slower than expected and has a lower execution rate of 279477.53125 executions per second. 3. JSON cloning with `JSON.parse(JSON.stringify())` is also slower, with a rate of 152437.125 executions per second. 4. The original implementation using `_` (Lodash) yields an average rate of 471645.6875 executions per second. Keep in mind that these results may vary depending on the specific use case and environment. What's your question or next step? Would you like to discuss any of these findings, explore optimization techniques, or something else?
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 (circles: true) vs Lodash cloneDeep vs JSON Clone
Comments
Confirm delete:
Do you really want to delete benchmark?