Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash unset vs lodash omit vs native delete
(version: 0)
Comparing performance of:
_.omit vs _.unset vs delete
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
Script Preparation code:
var o = {a:1,b:2,c:3,d:4}
Tests:
_.omit
o = _.omit(o, ['a', 'b'])
_.unset
_.unset(o, ['a', 'b'])
delete
delete o.a delete o.b
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
_.omit
_.unset
delete
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one month ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36 Edg/146.0.0.0
Browser/OS:
Chrome 146 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.omit
2257311.2 Ops/sec
_.unset
63393032.0 Ops/sec
delete
29774606.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested, compared, and their pros and cons. **What is tested?** The benchmark compares three approaches to remove or delete properties from an object: 1. **Native `delete` operator**: Directly deletes a property using the `delete` keyword. 2. **Lodash `_unset` function**: Uses Lodash's `_unset` function to remove a property from an object. 3. **Lodash `_omit` function**: Uses Lodash's `_omit` function to create a new object with certain properties removed. **Comparison options** The benchmark compares the performance of these three approaches across different test cases. * `_.omit` vs `_.unset`: This comparison tests how efficient each approach is when removing multiple properties from an object. * Each individual approach (Native `delete`, Lodash `_unset`, and Lodash `_omit`) is tested separately to compare their execution times. **Pros and cons of each approach:** 1. **Native `delete` operator**: * Pros: + Fastest way to delete a property, as it directly modifies the object's internal state. + No additional function calls or overhead from Lodash. * Cons: + Can be brittle if the property name changes, as it relies on the internal implementation of the object. + Not suitable for removing multiple properties at once. 2. **Lodash `_unset` function**: * Pros: + Portable and reliable, as Lodash's implementation is well-documented and maintained. + Can remove multiple properties in a single call. * Cons: + Slightly slower than the native `delete` operator due to the additional function call overhead. + May require additional setup or imports for certain environments. 3. **Lodash `_omit` function**: * Pros: + Similar to `_unset`, but creates a new object with the desired properties removed, rather than modifying the original object. + Can be useful when preserving the original object's state. * Cons: + Slightly slower than the native `delete` operator due to the additional function call overhead and creation of a new object. **Library: Lodash** Lodash is a popular JavaScript utility library that provides various functions for working with arrays, objects, and more. The `_unset` and `_omit` functions are part of Lodash's object manipulation suite, providing convenient ways to remove properties from objects or create new objects with specific properties removed. **Special JS feature: None** There are no special JavaScript features or syntaxes being tested in this benchmark. **Other alternatives** If you're looking for alternative approaches to removing properties from objects, some other options include: * Using the `Object.prototype.hasOwnProperty.call()` method to check if a property exists before deleting it. * Creating a custom function to remove properties using a loop and conditional statements. * Utilizing a library like Underscore.js or Ramda, which provide similar functions for object manipulation. Keep in mind that these alternatives may have different performance characteristics, trade-offs, or use cases compared to the native `delete` operator, Lodash `_unset`, and Lodash `_omit`.
Related benchmarks:
lodash unset vs object delete
Lodash omit vs Native object destruction
Unset vs Delete
lodash unset vs lodash omit
Comments
Confirm delete:
Do you really want to delete benchmark?