Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
structuredClone performance in daily objects
(version: 0)
Comparing performance of:
structuredClone vs daily deepclone
Created:
3 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var testObject = { myString: 'Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! ', myNumber: 123456789, myBoolean: true, myNull: null, myObject: { stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse: 'JSON.parse() method parses a JSON string...' }, myArray: [ 'hello world', 123456789, true, null, { hello: 'world' }, [{ hello: 'world' }, 1221, 1212, 'fdsaf', '3232', 'fdsaf', 'fdsa'] ], }; function deepClone(val) { if (typeof val !== 'object' || val === null) return val; if (Array.isArray(val)) { return val.map(item => deepClone(item)); } const obj = {}; for (const key in val) { obj[key] = deepClone(val[key]); } return obj; } var myCopy = null;
Tests:
structuredClone
myCopy = structuredClone(testObject)
daily deepclone
myCopy = deepClone(testObject)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
structuredClone
daily deepclone
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):
Let's break down the provided benchmark definition and test cases. **Benchmark Definition JSON** The benchmark is designed to measure the performance of two different cloning functions: `structuredClone` and a custom implementation called `deepClone`. * The **test object** (`testObject`) contains various types of data, including strings, numbers, booleans, null, objects, and arrays. This allows the benchmark to evaluate the performance of both cloning functions on different types of data. * The `structuredClone` function is a built-in JavaScript method introduced in ECMAScript 2020 (ES2020). It's designed to create a deep clone of an object, preserving all its properties and relationships. * The custom `deepClone` function is implemented by the test author. This implementation also creates a deep clone of the input object but uses a recursive approach. **Test Cases** There are two individual test cases: 1. **structuredClone**: This test case measures the performance of the built-in `structuredClone` function on the `testObject`. 2. **daily deepclone**: This test case measures the performance of the custom `deepClone` function implemented by the test author. **Options Compared** The benchmark compares two different approaches: * **structuredClone (built-in)**: The official JavaScript method for creating a deep clone of an object. * **custom deepClone**: A manually implemented recursive cloning function. **Pros and Cons of Each Approach** **Structured Clone (Built-in)** Pros: * **Efficient**: Built-in functions are typically optimized for performance, making them a good choice when possible. * **Easy to Use**: You don't need to write any custom code; it's straightforward to use. Cons: * **Platform Dependence**: The `structuredClone` function may not work in older browsers or environments that don't support it. * **Compatibility Issues**: Depending on the specific implementation, `structuredClone` might behave differently than expected, especially when dealing with complex objects and relationships. **Custom Deep Clone** Pros: * **Control**: You have full control over the cloning process, allowing for customization to suit your specific needs. * **Flexibility**: This approach can handle edge cases or non-standard data formats more easily than built-in methods. Cons: * **Code Complexity**: Implementing a deep clone by hand can be error-prone and harder to maintain. * **Performance Overhead**: Manual implementations might incur additional computational overhead compared to using built-in functions. **Other Considerations** When choosing between these approaches, consider the following factors: * **Maintenance**: How often will you update your cloning function? If it's rarely needed or updated, a custom implementation might be unnecessary. * **Data Complexity**: Are you dealing with complex objects or data formats that require special handling? * **Performance Requirements**: Is speed critical for your application? **Library Usage** In the provided benchmark definition, there is no explicit library usage mentioned. However, the `structuredClone` function itself relies on various libraries and internal implementations to provide its functionality. **Special JS Features or Syntax** There are no special JavaScript features or syntax explicitly used in this benchmark.
Related benchmarks:
JSON.stringify vs Deep Clone
Deep Clone vs JSON.Stringify vs structuredClone
2D nested array of numbers deep copy
deepclone vs deepfreeze vs saferdeepclone
deepclone vs deepfreeze vs saferdeepclone2
Comments
Confirm delete:
Do you really want to delete benchmark?