Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Angular Copy vs Lodash Copy
(version: 0)
compare object copy
Comparing performance of:
Angular copy vs Lodash Deep Clone
Created:
9 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.16.1/lodash.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js"></script>
Script Preparation code:
var obj = { "crossKey": "EURUSD", "dayLowPrice": 1.13045, "dayHighPrice": 1.13535, "previousClosePrice": 1.13215, "priceHist1": 107190404, "priceHist2": 250587665, "priceHist3": 765906410, "priceHist4": 274925633, "sparkline": 102925375, "spotPrice": 1.1307, "midPrice": 1.1307, "precision": 4, "percentChanged": -0.128, "threeMonthForecast": 1.08, "sixMonthForecast": 1.04, "tradable": true, "deliverable": true, "key": "EURUSD", "displayName": "EUR USD", "symbolId": "EURUSD", "objectId": 1, "assetType": "fx", "percentChange": -0.13, "selected": true, "lineChart": "9991581684158672254519078266440407", "barChart": [9, 43, 92, 47, 41, 21, 75, 32, 51, 19, 56, 97, 89, 36, 70, 2, 83, 61, 88, 47, 31, 54], "candleChart": "3869460804391469604270058742695196", "midPriceModel": "Price: key EURUSD, rate 1.1307, precision 4, appendFrac false, => 1.13 07 ", "spotPriceModel": "Price: key EURUSD, rate 1.1307, precision 4, appendFrac false, => 1.13 07 ", "crossCurrencies": ["EUR", "USD"], "unpackedSparkLine": { "price": 2, "priceDirection": 1, "fiveMinHigh": 4, "fiveMinLow": 0, "spike": 0, "scale": 30 }, "priceHistory": [3, 6, 7, 6, 4, 4, 7, 14, 31, 10, 16, 17, 22, 26, 13, 19, 15, 10, 8, 6, 6, 2, 2, 1] };
Tests:
Angular copy
angular.copy(obj);
Lodash Deep Clone
_.cloneDeep(obj);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Angular copy
Lodash Deep Clone
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/125.0.0.0 Safari/537.36
Browser/OS:
Chrome 125 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Angular copy
451504.6 Ops/sec
Lodash Deep Clone
181456.1 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark definition and test cases to understand what is being tested. **What is being tested?** The benchmark compares two approaches for creating a copy of an object: Angular's `copy()` function (also known as `angular.copy()`) and Lodash's `cloneDeep()` function. The test case creates a sample object `obj` with various properties, including arrays, objects, and other nested structures. **Options compared** The benchmark is testing the performance of two options: 1. **Angular's `copy()` function**: This function creates a shallow copy of the original object. 2. **Lodash's `cloneDeep()` function**: This function creates a deep copy of the original object, which means it recursively clones all nested objects and arrays. **Pros and Cons of each approach** **Angular's `copy()` function:** Pros: * Simple to use and understand * Fast execution time Cons: * Only creates a shallow copy, which may not be sufficient for complex data structures * May not work correctly with some object types (e.g., objects with functions as values) **Lodash's `cloneDeep()` function:** Pros: * Creates a deep copy of the original object, ensuring that all nested objects and arrays are properly cloned * More robust than Angular's `copy()` function for complex data structures Cons: * May have slower execution time due to the recursive cloning process * Requires Lodash library to be included in the test code **Library and its purpose** In this benchmark, two libraries are used: 1. **Angular**: A JavaScript framework for building web applications. 2. **Lodash**: A utility library that provides various functions for working with arrays, objects, and other data structures. The Angular library is used to define the `copy()` function being tested, while Lodash's `cloneDeep()` function is used as an alternative approach. **Special JS feature or syntax** There are no special JavaScript features or syntaxes being used in this benchmark. The code uses standard JavaScript syntax for object creation and array manipulation. **Other alternatives** If you want to test other approaches for creating a copy of an object, some alternatives could be: 1. **Using the `Object.assign()` method**: This method creates a shallow copy of an object by copying its enumerable own properties. 2. **Using the `JSON.parse(JSON.stringify(obj))` trick**: This trick creates a deep copy of an object by serializing it to a JSON string and then parsing it back into an object. Keep in mind that these alternatives may have different performance characteristics or requirements compared to Angular's `copy()` function and Lodash's `cloneDeep()` function.
Related benchmarks:
Angular Copy vs Angular Copy w/ Depth vs Lodash Copy vs Lodash Copy Deep vs JSON
Angular 1.7.5 Copy vs Lodash 4.17.11 Clone Deep
Angular Copy vs Lodash Clone
Angular Copy vs Lodash Copy (large-ish data)
Angular Copy vs Lodash Copy vs Object assign
Comments
Confirm delete:
Do you really want to delete benchmark?