Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
LoDash Omit vs Destructured undefined vs native delete
(version: 0)
Testing LoDash's omit function against Destructured undefined
Comparing performance of:
Native Destructure vs LoDash Omit vs LoDash Pick vs native delete
Created:
4 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.js"></script>
Script Preparation code:
var black = 'black' var green = 'green' var orange = 'orange' var red = 'red' var darkRed = 'darkRed' var blue = 'blue' var lightBlue = 'lightBlue' var navy = 'navy' var basePalette = { black, green, orange, red, darkRed, blue, lightBlue, navy }
Tests:
Native Destructure
var { orange: undefined, red: undefined, darkRed: undefined, ...coldPalette } = basePalette
LoDash Omit
_.omit(basePalette, ['orange','red', 'darkRed'])
LoDash Pick
_.pick(basePalette, ['blue', 'lightBlue', 'navy', 'black', 'green'])
native delete
const meta = Object.assign({}, basePalette); delete meta.orange; delete meta.red; delete meta.darkRed;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Native Destructure
LoDash Omit
LoDash Pick
native delete
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native Destructure
9258557.0 Ops/sec
LoDash Omit
1807712.6 Ops/sec
LoDash Pick
2065412.8 Ops/sec
native delete
5470868.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided JSON and benchmark preparation code to explain what's being tested, compared, and the pros/cons of each approach. **Benchmark Definition:** The test is comparing the performance of three approaches for removing or picking properties from an object: 1. **Native Destructure**: Directly destructuring the object using `const meta = Object.assign({}, basePalette);` followed by `delete meta.orange;`, `delete meta.red;`, and `delete meta.darkRed;`. 2. **LoDash Omit**: Using the `_omit()` function from Lodash to remove specified properties (`'orange'`, `'red'`, and `'darkRed'`) from the `basePalette` object. 3. **LoDash Pick**: Using the `_pick()` function from Lodash to select specific properties (`'blue'`, `'lightBlue'`, `'navy'`, `'black'`, and `'green'`) from the `basePalette` object. **Pros and Cons of each approach:** 1. **Native Destructure**: * Pros: + Lightweight, as it only involves a few operations. + Directly modifies the original object (if intended). * Cons: + May not be as efficient as other approaches for large objects or complex removal scenarios. + Can lead to unexpected behavior if not used carefully (e.g., using `delete` on non-existent properties). 2. **LoDash Omit**: * Pros: + Highly configurable, allowing for fine-grained control over which properties are removed. + Well-documented and widely adopted, making it easy to integrate with existing codebases. * Cons: + Requires an external library (Lodash), adding overhead in terms of size and potential compatibility issues. + May be slower than native approaches due to the additional function call and object iteration. 3. **LoDash Pick**: * Pros: + Similar advantages to `_omit()` in terms of configuration and flexibility. + Can also be used as a simple getter for specific properties, rather than just picking them from an object. * Cons: + Similar drawbacks as `_omit()`, including the need for an external library. **Library:** Lodash is a popular JavaScript utility library that provides a collection of functions for various tasks, such as array manipulation, object transformation, and more. In this benchmark, Lodash's `_omit()` and `_pick()` functions are used to test their performance compared to native approaches. **Special JS feature or syntax:** There doesn't appear to be any special JavaScript features or syntax being tested in this benchmark. The focus is on comparing the performance of different object manipulation techniques. **Alternatives:** Other alternatives for removing or picking properties from an object include: 1. **Using `Object.keys()` and `forEach()`**: Looping through an array of keys and deleting them using the `delete` operator. 2. **Using a library like Underscore.js**: Similar to Lodash, but with its own set of functions and features. 3. **Implementing a custom function**: Writing your own function to handle object manipulation, which may offer optimal performance or specific use cases. Keep in mind that the choice of approach depends on the specific requirements of your project, such as performance, code readability, and maintainability.
Related benchmarks:
Lodash omit vs Native delete
Lodash omit VS delete
Lodash omit vs Native object destruction
lodash unset vs lodash omit vs native delete
Lodash omit vs delete in b
Comments
Confirm delete:
Do you really want to delete benchmark?