Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash 4.17.15 omit vs es omit vs rest spread
(version: 0)
Comparing performance of:
Lodash vs Object desctruct vs rest operator
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/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:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
Browser/OS:
Chrome 127 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash
1611688.6 Ops/sec
Object desctruct
2645442.2 Ops/sec
rest operator
6528133.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided benchmark and explain what's being tested, compared, and analyzed. **Benchmark Overview** The benchmark compares three approaches to omit or remove specific keys from an object: 1. **Lodash**: Using the `_.omit` function from the Lodash library. 2. **Object Desctruct**: Using a custom implementation with destructuring assignment (Rest Operator). 3. **Custom Implementation**: A hand-crafted function that uses `Object.fromEntries`, `Object.entries`, and filtering to achieve the same result. **Options Compared** The benchmark tests the performance of these three approaches: * Lodash: `_.omit` function from the library. * Object Desctruct: Using a custom implementation with destructuring assignment (Rest Operator). * Custom Implementation: A hand-crafted function that uses `Object.fromEntries`, `Object.entries`, and filtering. **Pros and Cons** Here's a brief summary of each approach: 1. **Lodash**: Pros: * Well-maintained, widely used library. * Provides a consistent API for omitting keys. Cons: * Requires an additional dependency (Lodash library). 2. **Object Desctruct**: Pros: * Native JavaScript implementation, no external dependencies. * Efficient and concise code. Cons: * Limited to modern JavaScript environments (ES6+). 3. **Custom Implementation**: Pros: * Tailored to specific use case, potentially more efficient. Cons: * Requires manual implementation, which can be error-prone. **Library: Lodash** Lodash is a popular utility library for JavaScript that provides a wide range of functions for tasks like array manipulation, object transformation, and more. The `_.omit` function is part of this library and is used to remove specific keys from an object. **JavaScript Features/Syntax** The benchmark uses the following features: * **Destructuring assignment (Rest Operator)**: Introduced in ES6, it allows extracting multiple values from an array or object. * **Object.fromEntries()**: Introduced in ES2015, it creates a new object from key-value pairs. These features are used to implement the `Object Desctruct` approach and the custom implementation, respectively. **Alternative Approaches** Other alternatives for omitting keys from an object include: 1. Using a `for...in` loop and manual filtering. 2. Using `Array.prototype.filter()` on the object's key-value pairs (less efficient). 3. Using a different library or framework-specific solution (e.g., React's `useMemo` hook). Keep in mind that each approach has its trade-offs, and the best choice depends on the specific use case and performance requirements.
Related benchmarks:
lodash omit versus spread omit
lodash omit vs spread omit using babel
lodash merge vs object.assign vs spread (v2)
lodash omit vs spread omit modified
Spread Operator vs Lodash (v4.17.21)
Comments
Confirm delete:
Do you really want to delete benchmark?