Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
klona vs lodash.cloneDeep vs rfdc vs structuredClone vs structuredClone
(version: 6)
比较不同深度拷贝的test big ObjectData
Comparing performance of:
cloneDeep vs klona vs rfdc vs recursion vs structuredClone
Created:
3 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://unpkg.com/klona@2.0.4/json/index.js"></script> <script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script> <script src="https://cdn.jsdelivr.net/npm/rfdc@1.1.4/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" } ] }, { "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:
cloneDeep
myCopy = _.cloneDeep(sampleObject);
klona
myCopy = klona(sampleObject);
rfdc
var clone = rfdc({ proto: false,circles: false }); myCopy = clone(sampleObject);
recursion
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)
structuredClone
myCopy=structuredClone(sampleObject)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
cloneDeep
klona
rfdc
recursion
structuredClone
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
cloneDeep
19148.8 Ops/sec
klona
155750.8 Ops/sec
rfdc
115726.5 Ops/sec
recursion
33195.1 Ops/sec
structuredClone
19791.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
It seems like you're providing a template for benchmarking different cloning libraries in JavaScript, along with the actual benchmark results. To answer your question without leaving any part of the template untouched: For each library (klona, rfdc, recursion, structuredClone), compare their performance by looking at the "ExecutionsPerSecond" column. The library with the highest number of executions per second is likely to be the fastest. Here's a brief analysis based on the provided results: 1. **klona**: 291248.625 executions per second 2. **rfdc**: 258824.3125 executions per second 3. **recursion**: 148513.96875 executions per second 4. **structuredClone**: 57100.6328125 executions per second 5. **cloneDeep** (using lodash's `cloneDeep`): 34653.58203125 executions per second Based on these results, klona appears to be the fastest library for cloning objects in JavaScript, followed closely by rfdc. Please note that this analysis is based solely on the provided benchmark results and might not reflect the overall performance or other aspects of each library. Additionally, the actual performance can vary depending on specific use cases, input data, and system conditions.
Related benchmarks:
klona vs Lodash cloneDeep
RFDC clone vs Lodash cloneDeep vs JSON Clone vs structured clone
RFDC clone vs Lodash cloneDeep vs JSON Clone vs structuredClone
RFDC clone (circles: true) vs Lodash cloneDeep vs JSON Clone
Object Cloning Comparsion
Comments
Confirm delete:
Do you really want to delete benchmark?