Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
destructuring vs omit
(version: 1)
Comparing performance of:
omit vs destructure
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
import _ from "lodash";
Tests:
omit
let data = { asdasd: 'template123', someOtherField: 'value1', anotherField: 'value2' }; data = _.omit(data, 'asdasd')
destructure
let data = { asdasd: 'template123', someOtherField: 'value1', anotherField: 'value2' }; const { asdasd: _, ...dataRest } = data data = dataRest
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
omit
destructure
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Browser/OS:
Chrome 134 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
omit
1259580.4 Ops/sec
destructure
16043452.0 Ops/sec
Autogenerated LLM Summary
(model
gpt-4o-mini
, generated one year ago):
The benchmark currently under discussion compares two different approaches for removing a property from a JavaScript object: using the `omit` function from the Lodash library versus using JavaScript's object destructuring feature. Here’s a detailed explanation of what is being tested and the implications of each method. ### Options Being Compared 1. **Using Lodash's `omit` Function** - **Test Case**: ```javascript let data = { asdasd: 'template123', someOtherField: 'value1', anotherField: 'value2' }; data = _.omit(data, 'asdasd'); ``` - **Pros**: - **Readability**: The `omit` function is very intuitive, clearly stating the intention to remove a specific property from the object. - **Reusability**: Lodash provides a wide array of utility functions, so using `omit` can be beneficial when handling various operations across your codebase. - **Cons**: - **Performance**: The use of a library like Lodash may introduce overhead as it incurs additional function call overhead and may not be as performant as native operations, especially for simple tasks. - **Dependency**: This approach requires including Lodash, which may not be desirable in all projects, particularly in environments where bundle size is a critical consideration. 2. **Using JavaScript Object Destructuring** - **Test Case**: ```javascript let data = { asdasd: 'template123', someOtherField: 'value1', anotherField: 'value2' }; const { asdasd: _, ...dataRest } = data; data = dataRest; ``` - **Pros**: - **Native**: This approach uses JavaScript's built-in language features, which means no additional libraries are required. - **Performance**: Generally, destructuring can be more performant as it eliminates the overhead of calling an external function, as shown in the benchmark results. - **Cons**: - **Complexity**: For newcomers, destructuring might be less straightforward compared to the more explicit `omit` function, making it slightly harder to read for those not familiar with this syntax. - **Limited Use Cases**: This destructuring approach is good for certain cases but may not cover more complex use cases that the Lodash library would handle more robustly. ### Benchmark Results The benchmark results demonstrate a clear performance difference between the two approaches: - **Destructuring**: 17,959,386 executions per second. - **Omit**: 1,261,432 executions per second. From the results, it's evident that the destructuring method significantly outperformed the Lodash `omit` function, which further reinforces the argument for using native JavaScript features when performance is a critical concern. ### Conclusion In conclusion, if you are looking to simply remove properties from objects in a performant manner and you prefer to minimize external dependencies, JavaScript's object destructuring is the clear winner in this benchmark. However, if you require greater clarity or plan to utilize multiple utilities provided by Lodash, or if you are working within a codebase that already uses it extensively, `omit` can still be a practical choice. Each method has its place depending on specific project needs, team familiarity with JavaScript features, and performance requirements.
Related benchmarks:
deconstruct vs delete
merge vs set a value
comparison versus assignment 2
delete vs undefined vs null - 4
dot vs destructure syntax
destructuring vs creating
omit vs native delete
optionally chain me up on valentimes day - no safeword 2
Destructuring vs property access
Comments
Confirm delete:
Do you really want to delete benchmark?