Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Angular 1.5 clone vs Lodash 4.17 cloneDeep vs JSON Clone
(version: 0)
Comparing performance of:
Lodash cloneDeep vs Json clone vs Angular copy
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js"></script> <script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/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);
Json clone
myCopy = JSON.parse(JSON.stringify(MyObject));
Angular copy
myCopy = angular.copy(MyObject);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Lodash cloneDeep
Json clone
Angular copy
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36
Browser/OS:
Chrome 123 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash cloneDeep
1615919.4 Ops/sec
Json clone
1125934.5 Ops/sec
Angular copy
2639083.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and its test cases. **Benchmark Overview** The benchmark compares the performance of three different methods to create a deep copy of an object: Lodash `cloneDeep`, JSON's built-in `stringify` and `parse` methods, and Angular's `copy` method. The benchmark is designed to measure which approach is faster. **Test Cases** There are three test cases: 1. **Lodash cloneDeep**: This test case uses the `cloneDeep` function from Lodash to create a deep copy of the `MyObject`. The `cloneDeep` function is used for creating deep copies of objects, arrays, and maps. 2. **JSON Clone**: This test case uses JSON's built-in `stringify` method followed by `parse` method to create a deep copy of the `MyObject`. This approach converts the object to a string, creates a new object from the string, and then parses it back into an object. 3. **Angular Copy**: This test case uses Angular's `copy` function (not explicitly imported in this example) to create a deep copy of the `MyObject`. **Options Compared** The benchmark compares the following options: * Lodash `cloneDeep` * JSON's built-in `stringify` and `parse` methods * Angular's `copy` method **Pros and Cons of Each Approach** 1. **Lodash cloneDeep**: This approach is likely to be the fastest as it is specifically designed for creating deep copies of objects. * Pros: Fast, efficient, and widely used. * Cons: Requires an external library (Lodash). 2. **JSON Clone**: Using `stringify` and `parse` methods can lead to performance issues due to string conversion and parsing. * Pros: No external libraries required. * Cons: Slower, less efficient, and may cause issues with certain data structures. 3. **Angular Copy**: The existence of this option is unclear as the Angular code snippet seems incomplete or missing the import statement for `angular.copy`. However, if implemented correctly, it could be a competitive approach. * Pros: None are evident in this example. * Cons: Possibly slower than Lodash due to its nature and may require more overhead. **Other Considerations** The benchmark does not account for other factors that might affect performance, such as: * Data structure complexity * Object size and depth * Memory allocation and garbage collection It's essential to note that this benchmark is specifically designed to measure the performance of each approach in creating a deep copy of an object, rather than a comprehensive benchmarking exercise. **Alternatives** Other alternatives for creating deep copies include: * For JavaScript objects: `Object.assign({}, obj)` * For arrays: `Array.prototype.slice.call(arr)` * For Maps: `new Map([...])` Each of these approaches has its own trade-offs in terms of performance, readability, and maintainability.
Related benchmarks:
Angular clone vs Lodash cloneDeep vs JSON Clone
Angular clone vs Lodash clone vs JSON Clone vs Object.assign
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?