Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Angular clone vs Lodash cloneDeep
(version: 0)
Comparing performance of:
Lodash cloneDeep vs Angular copy
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.3/angular.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 = { 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:
Lodash cloneDeep
myCopy = _.cloneDeep(MyObject);
Angular copy
myCopy = angular.copy(MyObject);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash cloneDeep
Angular copy
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser/OS:
Chrome 120 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash cloneDeep
1730020.6 Ops/sec
Angular copy
2648191.8 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks on MeasureThat.net. **Benchmark Overview** The benchmark in question compares two approaches to create a deep copy of an object: AngularJS and Lodash. The test case uses a sample object `MyObject` with nested properties, including a JSON object (`jayson`) and various types (number, boolean, etc.). The goal is to measure the performance difference between using `angular.copy()` and `_cloneDeep()` from Lodash. **Options Compared** There are two main options being compared: 1. **AngularJS Copy**: Using `angular.copy(MyObject)` to create a deep copy of `MyObject`. 2. **Lodash Clone Deep**: Using `_cloneDeep(MyObject)` to create a deep copy of `MyObject`, courtesy of the Lodash library. **Pros and Cons** ### AngularJS Copy Pros: * Lightweight: As part of the AngularJS framework, this approach is relatively small in size (around 30 KB). * Familiarity: If you're already using AngularJS, this approach might feel more familiar and easier to use. Cons: * Limited flexibility: The `angular.copy()` method only works with objects that are serializable, which might limit its usage. * Potential side effects: Depending on the implementation, `angular.copy()` might not create a deep copy of all nested properties. ### Lodash Clone Deep Pros: * General-purpose: `_cloneDeep()` is part of a more extensive library (Lodash) with many other utility functions, making it a versatile choice. * Robustness: The implementation of `_cloneDeep()` has been extensively tested and is designed to handle various types and nested structures. Cons: * Larger size: As part of the Lodash library, this approach requires including an additional dependency (~70 KB). **Library Overview** The `lodash` library (specifically, the `cloneDeep` function) provides a more comprehensive set of utility functions for working with data. The `_cloneDeep()` function is designed to create deep copies of objects, which can be particularly useful in many JavaScript applications. **Special JS Feature/Syntax** None mentioned in this benchmark. **Other Alternatives** If you're looking for alternative approaches to deep copying objects, consider: 1. **JSON.parse(JSON.stringify(obj))**: This method creates a shallow copy of the object, but it's often sufficient for simple cases. 2. **Object.assign()**: While not designed specifically for deep copying, `Object.assign()` can be used in conjunction with other methods (e.g., `JSON.parse`) to achieve the desired result. Keep in mind that each approach has its trade-offs in terms of performance, size, and flexibility. The choice ultimately depends on your specific use case and requirements.
Related benchmarks:
Angular clone vs Lodash clone vs JSON Clone vs Object.assign
Angular 1.5 clone vs Lodash 4.17 cloneDeep vs JSON Clone
Angular clone vs Lodash cloneDeep vs JSON Clone 1.5.10
Big Angular clone vs Lodash cloneDeep vs JSON Clone 1.5.10
Angular clone vs Lodash clone (shallow) vs JSON Clone
Comments
Confirm delete:
Do you really want to delete benchmark?