Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash omit vs native function
(version: 0)
Comparing performance of:
lodash omit vs native function
Created:
3 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>
Script Preparation code:
function omit(obj, props) { const newObj = {}; for (let prop in obj) { if (!props.includes(prop)) { newObj[prop] = obj[prop]; } } return newObj; }
Tests:
lodash omit
const myObj = { name: 'John', age: 30, city: 'New York', country: 'USA' }; const newObj = _.omit(myObj, ['city', 'country']);
native function
const myObj = { name: 'John', age: 30, city: 'New York', country: 'USA' }; const newObj = omit(myObj, ['city', 'country']);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash omit
native function
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):
The provided benchmark compares the performance of two approaches to remove specific properties from an object: Lodash's `omit` function and a native JavaScript implementation. **Lodash's `omit` function:** * Description: Lodash is a popular JavaScript library that provides various utility functions. The `omit` function takes an object and an array of property names as input, and returns a new object with the specified properties removed. * Library purpose: To provide a convenient way to remove specific properties from objects in a concise and readable manner. **Native JavaScript implementation:** * Description: The native implementation is a custom function that achieves the same result as Lodash's `omit` function. It iterates over each property in the input object, checks if it exists in the array of excluded properties, and only includes it in the new object if it doesn't. * Pros: + No external dependency on a library. + Potential for better performance since it doesn't involve a function call to Lodash. * Cons: + Requires more code and effort to implement. + May be less readable or maintainable, especially for complex exclusion logic. **Comparison:** The benchmark compares the two approaches using the same input object (`myObj`) and excluding the same properties (`['city', 'country']`). The results show that: * The native implementation outperforms Lodash's `omit` function in terms of executions per second. * However, the execution times are relatively close, suggesting that both approaches have acceptable performance. **Other considerations:** * Error handling: Both implementations assume that the input object and exclusion array are valid. In a real-world scenario, you might want to add error handling for cases like invalid inputs or typos in the exclusion array. * Code maintainability: While the native implementation is more concise, it may be harder to read and understand due to its simplicity. Lodash's `omit` function provides a clear and readable API. * Library choice: If you need to perform this operation frequently or want to leverage other Lodash functions, using the library might be a better choice. **Alternatives:** * Other libraries that provide similar functionality to Lodash's `omit` include: + Underscore.js + Ramda + Moment.js (for more complex filtering) * Native JavaScript alternatives for removing properties from objects might include: + Using the `Object.keys()` and `forEach()` methods in combination. + Utilizing the `reduce()` method to build a new object. Keep in mind that these alternatives may not provide the same level of convenience, readability, or performance as Lodash's `omit` function.
Related benchmarks:
lodash omit vs spread omit vs spread omit using babel
lodash omit vs spread omit using babel
lodash omit vs spread omit vs delete omit
Lodash omit vs Native object destruction
lodash omit vs spread omit modified
Comments
Confirm delete:
Do you really want to delete benchmark?