Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
klona vs structuredClone
(version: 0)
https://developer.mozilla.org/en-US/docs/Web/API/structuredClone
Comparing performance of:
klona vs Native structuredClone
Created:
3 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://unpkg.com/klona@2.0.6/json/index.min.js'></script>
Script Preparation code:
var MyObject = { description: 'Creates a deep copy of source, which should be an object or an array.', myNumber: 123456789, myBoolean: true, jayson: { stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse: 'JSON.parse() method parses a JSON string...' } }; var myCopy = null;
Tests:
klona
myCopy = klona.klona(MyObject);
Native structuredClone
myCopy = structuredClone(MyObject);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
klona
Native structuredClone
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
6 months ago
)
User agent:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Mobile Safari/537.36
Browser/OS:
Chrome Mobile 141 on Android
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
klona
3010161.8 Ops/sec
Native structuredClone
191567.3 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the Benchmark Definition JSON and the individual test cases. **What is tested?** The benchmark tests two approaches to create a deep copy of an object: `klona` (a third-party library) and the native JavaScript method `structuredClone`. **Options compared** The two options being compared are: 1. **Klona**: A third-party library that provides a simple way to create a deep copy of objects. 2. **Native structuredClone**: The built-in JavaScript method that creates a deep copy of objects. **Pros and Cons** Here's a brief summary of the pros and cons of each approach: * **Klona**: + Pros: Easy to use, simple API, and efficient. + Cons: A third-party library, which means there may be additional dependencies or complexity. * **Native structuredClone**: + Pros: Built-in method, no additional dependencies required, and optimized for performance. + Cons: May not be supported in older browsers or versions of JavaScript. **Library description** The `klona` library is a simple and efficient way to create a deep copy of objects. It provides a single function, `klona`, that takes an object as input and returns a new copy of the object. **Special JS feature or syntax** There are no special features or syntax used in this benchmark. The code is straightforward and uses standard JavaScript features. **Other alternatives** If you're interested in creating deep copies of objects without using libraries, you can also use other approaches such as: * Using `Object.assign()` to create a shallow copy, and then recursively creating a new object for each property. * Using `JSON.parse(JSON.stringify(obj))` to create a deep copy. However, this method can be slower and more memory-intensive. Here's an example of how you might implement a custom deep copying function: ```javascript function deepCopy(obj) { if (typeof obj !== 'object') return obj; const copy = Array.isArray(obj) ? [] : {}; for (const key in obj) { copy[key] = deepCopy(obj[key]); } return copy; } ``` However, using a library like `klona` or the native `structuredClone` method is usually the simplest and most efficient way to create deep copies of objects.
Related benchmarks:
Lodash cloneDeep vs structuredClone vs Klona 3
Lodash cloneDeep vs structuredClone deep array
Lodash cloneDeep vs structuredClone vs naive JSON.stringify
Lodash cloneDeep vs structuredClone vs JSON Parse (deep object)
Lodash cloneDeep vs structuredClone vs JSON-JSON
Comments
Confirm delete:
Do you really want to delete benchmark?