Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Angular 1.7.5 Copy vs Lodash 4.17.11 Clone Deep
(version: 0)
compare object copy
Comparing performance of:
Angular Copy vs Lodash Deep Clone
Created:
7 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/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:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks. **Benchmark Definition** The provided JSON represents two benchmark definitions: 1. **Angular Copy**: Measures how fast `angular.copy(obj)` executes. 2. **Lodash Deep Clone**: Measures how fast `_cloneDeep(obj)` from Lodash library executes. **Options Compared** Both benchmarks compare the execution time of two different approaches to create a copy or clone an object: * **Angular Copy**: Uses Angular's built-in `copy` function, which creates a shallow copy of an object. * **Lodash Deep Clone**: Uses Lodash's `_cloneDeep` function, which creates a deep copy of an object, recursively cloning all nested properties. **Pros and Cons** ### Angular Copy Pros: * Fast: Angular's `copy` function is optimized for performance and likely to be very fast. * Lightweight: No additional dependencies are required. Cons: * Only creates a shallow copy: The new object will reference the same inner objects as the original, which may not be desirable in all cases. * Limited control over cloning process: Angular's implementation of `copy` is internal and may not allow for customization or control over the cloning process. ### Lodash Deep Clone Pros: * Creates a deep copy: Recursively clones all nested properties, ensuring that new objects are independent and non-referential. * Highly customizable: Allows for modification of the cloning process through Lodash's API. Cons: * Slower: The `_cloneDeep` function is more complex and may be slower than Angular's `copy` function. * Additional dependency: Requires including Lodash in the project, which adds overhead to the build process. **Library and Purpose** In this benchmark, Lodash's `_cloneDeep` function is used. Lodash is a popular utility library for JavaScript that provides a wide range of functions for tasks such as: * Array manipulation * Object manipulation (e.g., `cloneDeep`, `assign`, etc.) * String manipulation * Function utility The purpose of `_cloneDeep` is to create a deep copy of an object, recursively cloning all nested properties. This can be useful in various scenarios where you need to create a new, independent copy of an object. **Special JavaScript Feature or Syntax** There doesn't appear to be any special JavaScript feature or syntax being tested here. The focus is on comparing the execution speed of two different approaches to create a copy or clone an object using well-established libraries (Angular and Lodash). **Other Alternatives** For creating deep copies of objects, other alternatives include: * **JSON.parse(JSON.stringify(obj))**: A simple and widely available approach that creates a new object by recursively copying properties from the original. * **for...in` loop + `Object.assign()`**: A manual implementation using a for...in loop to iterate over the object's properties and create a new object using `Object.assign()`. * **ES6 Spread Operator (`{...obj}`)**: A modern approach that creates a shallow copy of an object by spreading its properties into a new object. Keep in mind that these alternatives may have different performance characteristics, trade-offs, or limitations compared to the Lodash `_cloneDeep` function.
Related benchmarks:
Angular Copy vs Lodash Copy
Angular Copy vs Angular Copy w/ Depth vs Lodash Copy vs Lodash Copy Deep vs JSON
Angular Copy vs Lodash Clone
Angular Copy vs Lodash Copy (large-ish data)
Comments
Confirm delete:
Do you really want to delete benchmark?