Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
klona vs core-js structuredClone vs Lodash cloneDeep
(version: 4)
Comparing performance of:
klona vs structuredClone vs cloneDeep
Created:
3 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://unpkg.com/klona@2.0.5/dist/index.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/core-js/3.23.4/minified.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js"></script>
Script Preparation code:
var MyObject = [{ "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:
klona
myCopy = klona(MyObject);
structuredClone
myCopy = structuredClone(MyObject);
cloneDeep
myCopy = _.cloneDeep(MyObject);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
klona
structuredClone
cloneDeep
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36
Browser/OS:
Chrome 145 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
klona
553296.1 Ops/sec
structuredClone
184536.9 Ops/sec
cloneDeep
105861.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll do my best to break down the provided benchmark and explain what's being tested, compared, and discussed. **Benchmark Overview** The benchmark compares the performance of three cloning functions: 1. `klona`: A JavaScript library for creating shallow and deep clones of objects. 2. `structuredClone`: A built-in JavaScript function introduced in ECMAScript 2020 (ES12) that creates a deep clone of an object. 3. `_.cloneDeep` from the Lodash library: A utility function for creating deep copies of objects. **What's being tested** The benchmark tests how quickly each cloning function can create a copy of a large, nested JSON object (`MyObject`). The test measures the number of executions per second (ExecutionsPerSecond) for each function on various browsers and devices. **Comparison of cloning approaches** Here are some pros and cons of each cloning approach: 1. **klona**: * Pros: Can create shallow clones as well as deep clones, which might be beneficial for certain use cases. * Cons: May not work correctly with circular references (i.e., objects that reference themselves) or very large objects due to memory constraints. 2. **structuredClone**: * Pros: Built-in and efficient, works correctly with circular references, and is designed for deep cloning. * Cons: Only available in modern browsers (Chrome 129 and above), which might limit the benchmark's relevance for older browsers. 3. **_.cloneDeep` from Lodash**: * Pros: Works well with circular references and can handle large objects efficiently. * Cons: Requires an external library, which might introduce additional overhead. **Other considerations** 1. **Memory usage**: The benchmark assumes that the cloning functions will create a new copy of the original object in memory. This might not be the case for very large objects or those with sensitive data (e.g., encryption keys). 2. **Performance optimization**: Some browsers or devices might have performance optimizations in place that affect the benchmark's results. **Browser and device variations** The benchmark measures performance across different browsers (Chrome 129) and devices (Desktop), which might influence the results due to differences in: 1. CPU architecture 2. Memory constraints 3. Browser-specific optimizations Overall, this benchmark provides insight into the performance differences between various cloning functions, but keep in mind the potential limitations mentioned above.
Related benchmarks:
klona vs Lodash cloneDeep
RFDC clone vs Lodash cloneDeep vs JSON Clone vs structuredClone
RFDC clone (circles: true) vs Lodash cloneDeep vs JSON Clone
klona vs core-js structuredClone vs Lodash cloneDeep vs json parse stringify
Comments
Confirm delete:
Do you really want to delete benchmark?