Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash omit vs Native Delete for multiple key removal
(version: 0)
Comparing performance of:
Native multiple delete vs Lodash multiple omit
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="lodash.js"></script>
Script Preparation code:
data = { abf: 'asd', message: 'koko', abf2: 'asd2', abf3: 'asd3', abf4: 'asd4', abf5: 'asd5', abf6: 'asd6', abf7: 'asd7', abf8: 'asd8', abf9: 'asd9' }
Tests:
Native multiple delete
const meta = Object.assign({}, data); ['abf1', 'abf2', 'abf5', 'abf7', 'abf9'].forEach(e => delete meta[e]); return { message: data, meta }
Lodash multiple omit
return { message: data, meta: _.omit(data, ['abf1', 'abf2', 'abf5', 'abf7', 'abf9']) }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Native multiple delete
Lodash multiple omit
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
10 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Browser/OS:
Chrome 137 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native multiple delete
3433953.8 Ops/sec
Lodash multiple omit
1186478.8 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and its test cases. **Benchmark Purpose** The purpose of this benchmark is to compare two approaches for removing multiple keys from an object: using the `delete` operator (native approach) and using the `omit` function from the Lodash library (Lodash approach). **Options Compared** Two options are being compared: 1. **Native Delete**: This approach uses the `delete` operator to remove the specified keys from the `meta` object. 2. **Lodash Multiple Omit**: This approach uses the `omit` function from the Lodash library to remove the specified keys from the `data` object. **Pros and Cons** **Native Delete** Pros: * Native implementation, so it's likely to be faster and more efficient. * No external dependencies required. Cons: * Can be less readable and maintainable, as it requires using the `delete` operator in a loop. * May not handle edge cases or errors as well as Lodash. **Lodash Multiple Omit** Pros: * More readable and maintainable, as it uses a single function call to remove keys. * Handles edge cases and errors better than native delete. Cons: * Requires an external dependency (Lodash library). * May be slower due to the overhead of loading the library. **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for common tasks, such as array manipulation, object modification, and more. The `omit` function is used in this benchmark to remove keys from an object. **Special JS Feature/Syntax** None mentioned in the provided code snippet. **Other Alternatives** If you prefer not to use Lodash or the `delete` operator, other alternatives for removing multiple keys from an object include: * Using a library like Underscore.js (another popular utility library) * Implementing your own custom function for removing keys * Using a alternative data structure, such as a Map or a Set, that doesn't require explicit key removal. For example, you could use the following code to remove multiple keys from an object using a custom function: ```javascript function removeKeys(obj, keys) { return Object.keys(obj).reduce((newObj, key) => { if (!keys.includes(key)) { newObj[key] = obj[key]; } return newObj; }, {}); } ``` This approach is more readable and maintainable than the native delete approach, but may be slower due to the overhead of creating a new object.
Related benchmarks:
Lodash omit vs Native delete
_.omit vs delete of map
omit vs delete
delete vs lodash.omit
Comments
Confirm delete:
Do you really want to delete benchmark?