Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
DeeplClone vs StructuredClone
(version: 1)
Comparing performance of:
FAST JSON-patch vs Native
Created:
11 months ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script type='text/javascript' src="https://cdn.jsdelivr.net/npm/jsondiffpatch/dist/jsondiffpatch.umd.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/deep-diff@1/dist/deep-diff.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/fast-json-patch/dist/fast-json-patch.min.js"></script>
Script Preparation code:
obj1= { name: "Argentina", cities: [ { name: 'Buenos Aires', population: 13028000, }, { name: 'Cordoba', population: 1430023, }, { name: 'Rosario', population: 1136286, }, { name: 'Mendoza', population: 901126, }, { name: 'San Miguel de Tucuman', population: 800000, } ] }; obj2= { name: "Argentina", cities: [ { name: 'Cordoba', population: 1430023, }, { name: 'Mendoza', population: 901126, }, { name: 'San Miguel de Tucuman', population: 550000, } ] };
Tests:
FAST JSON-patch
var objnew = jsonpatch.deepClone(obj1);
Native
var objnew = structuredClone(obj1);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
FAST JSON-patch
Native
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; rv:140.0) Gecko/20100101 Firefox/140.0
Browser/OS:
Firefox 140 on Mac OS X 10.15
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
FAST JSON-patch
948294.9 Ops/sec
Native
722996.6 Ops/sec
Autogenerated LLM Summary
(model
gpt-4o-mini
, generated 11 months ago):
The provided benchmark compares two different approaches for deep cloning JavaScript objects: one using a library called `fast-json-patch`, specifically its `deepClone` method, and the other using the native `structuredClone` function. ### Benchmark Overview 1. **Benchmark Participants**: - **FAST JSON-patch**: Utilizes the `deepClone` method from the `fast-json-patch` library to create a deep copy of an object. - **Native**: Utilizes the native JavaScript `structuredClone` function, which is part of the ECMAScript standard. ### Pros and Cons of Each Approach #### 1. FAST JSON-patch - **Pros**: - Offers deep cloning capabilities with additional features for tracking changes between objects and for applying patches efficiently. - Can handle complex scenarios involving references, arrays, and objects with circular references. - **Cons**: - Slightly heavier due to the additional overhead of the library. - Performance may vary based on the complexity of the data structure, though the benchmark indicates it is faster than the native alternative in this specific case. #### 2. Native (structuredClone) - **Pros**: - Built into the JavaScript language, meaning no external libraries are required for usage. - Handles most types of objects accurately, including special cases like `Date` objects, `Map`, and `Set`. - **Cons**: - Not available in all environments; support needs to be verified based on the JavaScript engine being used. - In some cases, it might be slower than optimized library functions, as seen in this benchmark. ### Other Considerations - The benchmark indicates the **executions per second**, highlighting that the `FAST JSON-patch` can perform approximately 442,543 executions per second, whereas `structuredClone` performs around 159,083 executions per second. - While performance is a critical factor, it’s also essential to consider the ease of use, readability of the code, and the necessity of including an additional dependency in your project. ### Alternatives - **Lodash**: Another popular library that provides a `cloneDeep` method for deep cloning objects. It is mature, widely used, and has comprehensive utility functions. - **JSON Serialization**: `JSON.parse(JSON.stringify(obj))` can be used to manually clone objects, but this method has limitations, such as the inability to handle `Date`, functions, or undefined values. - **Manual Cloning**: Depending on the specific data structure you are working with, manually creating a deep copy using loops or recursion could sometimes be efficient. In summary, the benchmark effectively compares the performance of cloning methods in JavaScript, focusing on usability, performance, and the environments where each method is applicable. The choice between using a library or a native approach will heavily depend on the specific requirements of the application, including performance constraints and the complexity of the objects being cloned.
Related benchmarks:
Bench different js diff methods
Bench fast-json-patch vs jsondiffpatch
Bench fast-json-patch vs deep-diff
Bench fast-json-patch apply vs fast-json-patch mutate
Bench fast-json-patch vs jsondiffpatch icl. Patching
Deletion: splice vs filter vs loop
Bench fast-json-patch vs microdiff
Bench fast-json-patch vs jsondiffpatch vs rfc6902
Bench fast-json-patch vs jsondiffpatch deep clone ver
Comments
Confirm delete:
Do you really want to delete benchmark?