Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
_.omit vs delete of map
(version: 0)
Perf lodash.omit vs Object.keys().filter
Comparing performance of:
Delete of map vs Omit
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js"></script>
Script Preparation code:
data = { a:'koko',b:'koko',c:'koko',d:'koko',e:'koko',f:'koko',g:'koko',h:'koko',i:'koko',x:'asd' }
Tests:
Delete of map
['a','x'].map(key => delete data.key) return data
Omit
return _.omit(data, ['a','x'])
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Delete of map
Omit
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/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Delete of map
24716110.0 Ops/sec
Omit
1559007.9 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the explanation of the provided benchmark. **Overview** The benchmark measures the performance difference between using `delete` to remove properties from an object (`_.omit`) and using `Object.keys().filter()` (along with Lodash's `omit` function) in JavaScript. **Options being compared** Two approaches are being compared: 1. **Direct deletion**: Using `delete data.key` to remove properties from the `data` object. 2. **Lodash's omit**: Using Lodash's `_omit` function to filter out specific keys from the `data` object. **Pros and Cons of each approach:** **Direct Deletion (Delete)** Pros: * Typically faster, as it avoids the overhead of function calls and array operations. * Often considered more "native" or efficient way to remove properties from an object. Cons: * May not work correctly if the property names are strings that contain special characters or non-ASCII values. * Can lead to unexpected behavior if used with nested objects (i.e., `data.a` would delete `a` from both the top-level and any nested objects). **Lodash's Omit** Pros: * More predictable and robust, as it handles string property names correctly and ignores properties that don't match the filter. * Often considered more readable and maintainable, especially for complex filtering scenarios. Cons: * May be slower due to the overhead of function calls and array operations. * Relies on Lodash's implementation, which may have internal optimizations or quirks not apparent from the surface. **Library usage** Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks like string manipulation, array processing, and more. In this benchmark, Lodash's `_omit` function is used to filter out specific keys from the `data` object. **Special JS feature/syntax** None mentioned in this explanation. However, it's worth noting that some JavaScript features or syntax might affect the performance of these approaches (e.g., using `let` or `const` instead of `var` for variable declarations). But in this case, no specific features are being leveraged. **Other alternatives** For those looking to optimize object removal in JavaScript, consider: * Using a library like Lodash's own `omit` function, as it provides a more predictable and robust way to filter objects. * Implementing your own custom filtering functions using techniques like `Object.keys()` or `for...in`. * Using modern JavaScript features like `Map` or `Set` to represent the object's properties (if available in older browsers). Keep in mind that performance optimizations should always be evaluated on a per-project basis, considering factors like data size, complexity, and specific use cases.
Related benchmarks:
Filter-Map: Lodash vs Native
Filter-Map: Lodash chain vs Native
native lodash filter map
native lodash filter map 2
Comments
Confirm delete:
Do you really want to delete benchmark?