Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
npm clone libv2
(version: 0)
Comparing performance of:
lodash cloneDeep vs npm clone lib vs structuredClone
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js'></script> <script src='https://cdn.jsdelivr.net/npm/clone@2.1.2'></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; var cloneLib = clone
Tests:
lodash cloneDeep
myCopy = _.cloneDeep(MyObject);
npm clone lib
myCopy = cloneLib(MyObject)
structuredClone
myCopy = structuredClone(MyObject)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
lodash cloneDeep
npm clone lib
structuredClone
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Browser/OS:
Chrome 124 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash cloneDeep
480547.1 Ops/sec
npm clone lib
523471.4 Ops/sec
structuredClone
226881.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to help explain the provided benchmark. **Benchmark Overview** The benchmark compares three different approaches for creating a deep copy of an object in JavaScript: 1. **npm clone lib**: This method uses the `clone` function from the `clone` library, which is available via npm. 2. **lodash cloneDeep**: This method uses the `cloneDeep` function from the Lodash library, which is a popular utility library for functional programming in JavaScript. 3. **structuredClone**: This method is a built-in JavaScript feature introduced in ECMAScript 2020 (ES2020) that creates a deep copy of an object. **Options Compared** The benchmark compares the performance of these three approaches on a sample input object `MyObject`. The input object has nested properties, including arrays and objects, which require deep copying to create a new copy. **Pros and Cons of Each Approach:** * **npm clone lib**: This approach uses a dedicated library for cloning objects. It is likely to be efficient but may introduce additional overhead due to the library's functionality. * **lodash cloneDeep**: Lodash is a widely used utility library, and its `cloneDeep` function is designed to create deep copies of complex data structures. This approach is likely to be performant, as it leverages optimized implementation details within the Lodash library. However, it introduces an external dependency on the Lodash library. * **structuredClone**: As a built-in JavaScript feature, this approach does not introduce any external dependencies or libraries. It is optimized for performance and should provide good results out of the box. **Library Descriptions:** * **Lodash Library**: The Lodash library is a comprehensive utility library that provides various functions for common programming tasks in JavaScript. Its `cloneDeep` function creates a deep copy of an object, handling nested arrays and objects correctly. * **Clone Library**: The Clone library is a dedicated library for cloning objects in JavaScript. It provides a lightweight implementation of deep copying, which may be more efficient than the Lodash `cloneDeep` function. **Special JS Features or Syntax:** * **structuredClone**: This feature was introduced in ECMAScript 2020 (ES2020) as a built-in method for creating deep copies of objects. It is supported by most modern browsers and Node.js versions. **Other Considerations:** * The benchmark's performance results may vary depending on the specific use case, input data, and JavaScript runtime environment. * In addition to these three approaches, other methods like JSON.parse() + JSON.stringify() or for...of loops could be used to create deep copies of objects. However, these methods are not as efficient as the approaches presented in the benchmark. **Alternatives:** * Other libraries that provide deep copying functionality include `deep-clone` and `copy-deep`.
Related benchmarks:
Lodash cloneDeep vs JSON Clone with huge object
Lodash cloneDeep vs clone
Lodash (4.17.11) cloneDeep vs JSON Clone
Lodash cloneDeep vs JSON Clone with Array
npm clone lib vs lodash cloneDeep
Comments
Confirm delete:
Do you really want to delete benchmark?