Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash omit vs es omit vs rest spread
(version: 0)
Comparing performance of:
Lodash vs Object desctruct vs rest operator
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.5/lodash.min.js'></script>
Tests:
Lodash
const obj = { a:1, b:1, c:1, d:1, e:1, f:1, g:1, h:1, i:1, } const n = _.omit(obj, ['a','d','i']);
Object desctruct
const obj = { a:1, b:1, c:1, d:1, e:1, f:1, g:1, h:1, i:1, } const omit = (originalObj = {}, keysToOmit = []) => Object.fromEntries( Object.entries(originalObj) .filter(([key]) => !keysToOmit.includes(key)) ) const n = omit(obj, ['a','d','i']);
rest operator
const obj = { a:1, b:1, c:1, d:1, e:1, f:1, g:1, h:1, i:1, } const { a, d, i, ...n } = obj;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Lodash
Object desctruct
rest operator
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
10 months ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36
Browser/OS:
Chrome 138 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash
1003651.6 Ops/sec
Object desctruct
2617052.5 Ops/sec
rest operator
5839856.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 is designed to compare the performance of three different approaches for removing specific keys from an object: 1. **Lodash omit**: Uses the `_.omit()` function from the Lodash library to remove specified keys from an object. 2. **Object destructuring with rest operator**: Uses the rest operator (`...`) to create a new object that excludes certain properties. 3. **Custom implementation with Object.fromEntries() and filter()**: A custom implementation using `Object.fromEntries()` and `filter()` to achieve similar results. **Options Compared** The benchmark compares the performance of these three approaches: * **Pros and Cons of each approach:** + Lodash omit: - Pros: Easy to use, well-maintained library with a wide range of utility functions. - Cons: Adds an extra dependency to the project, may have a slower execution time due to the overhead of the library. + Object destructuring with rest operator: - Pros: Lightweight, concise syntax, and good performance since it only creates a new object without modifying the original one. - Cons: Limited to JavaScript 12+ syntax, may require additional setup for older browsers or environments. + Custom implementation: - Pros: Tailored for this specific use case, potentially optimized for better performance. - Cons: More complex codebase, requires manual optimization and testing. * **Other considerations:** + The benchmark assumes that the input objects are large enough to benefit from the optimizations provided by these approaches. For small objects or simple key removals, other factors like memory allocation and garbage collection might become more significant than performance differences between these approaches. **Library and Special JS Features** * **Lodash**: A popular JavaScript utility library providing a wide range of functions for tasks such as string manipulation, array operations, and object transformation. `_.omit()` is used to remove specified keys from an object. * **Rest operator (`...`)**: Introduced in JavaScript 12 (and later), this syntax allows for the creation of new objects that exclude certain properties. **Test Case Explanation** Each test case consists of a benchmark definition, which includes: 1. A sample object with multiple keys. 2. The approach to be tested (Lodash omit, Object destructuring with rest operator, or custom implementation). 3. A call to the function being benchmarked, passing in the object and an array of key names to omit. **Alternatives** Other alternatives for removing specific keys from objects include: * **Using `Object.keys()`**, `Array.prototype.filter()`, and `Object.assign()`**: This approach involves manually iterating over the object's keys using `Object.keys()` and filtering out the unwanted ones. However, it can be less efficient than the approaches compared in this benchmark. * **Utilizing `for...in` loops or `forEach()` methods**: Similar to the previous alternative, these loops can iterate over the object's properties but are generally considered slower and more verbose. Keep in mind that the choice of approach often depends on the specific requirements and constraints of your project.
Related benchmarks:
lodash omit versus spread omit
lodash omit vs spread omit using babel
lodash merge vs object.assign vs spread (v2)
lodash merge vs object.assign vs spread (v3)
lodash omit vs spread omit modified
Comments
Confirm delete:
Do you really want to delete benchmark?