Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
LoDash Omit vs Destructured undefined vs real native vs object assign
(version: 0)
Testing LoDash's omit function against Destructured undefined
Comparing performance of:
Native Destructure vs LoDash Omit vs LoDash Pick vs Object assign
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.js"></script>
Script Preparation code:
var black = 'black' var green = 'green' var orange = 'orange' var red = 'red' var darkRed = 'darkRed' var blue = 'blue' var lightBlue = 'lightBlue' var navy = 'navy' var basePalette = { black, green, orange, red, darkRed, blue, lightBlue, navy }
Tests:
Native Destructure
let oldPalette = basePalette; basePalette = { orange: undefined, red: undefined, darkRed: undefined, ...oldPalette };
LoDash Omit
_.omit(basePalette, ['orange','red', 'darkRed'])
LoDash Pick
_.pick(basePalette, ['blue', 'lightBlue', 'navy', 'black', 'green'])
Object assign
basePalette = Object.assign(basePalette, {orange: undefined, red: undefined, darkRed: undefined})
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Native Destructure
LoDash Omit
LoDash Pick
Object assign
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):
Measuring performance in JavaScript microbenchmarks like this one is crucial to understand how different approaches affect the execution speed of various libraries and native JavaScript features. **Benchmark Overview** The provided benchmark compares four methods for filtering or manipulating objects: LoDash's `omit` function, Destructured undefined, Native destructuring, and Object.assign. The goal is to measure their performance in a set of test cases that involve removing properties from the base palette object. **Test Cases and Approaches** There are four individual test cases: 1. **Native Destructure**: This approach uses JavaScript's native destructuring feature to extract properties from the `basePalette` object. The idea is to destructure only the properties that should be kept, leaving the rest as undefined. 2. **LoDash Omit**: LoDash's `omit` function removes specified properties from an object. In this case, it's used with an array of property names to exclude from the base palette. 3. **LoDash Pick**: This test case uses LoDash's `pick` function to extract specific properties from the base palette, effectively filtering out the rest. 4. **Object assign**: The Object.assign method is used to create a new object by assigning values from another object into it. In this case, it's used to add some properties while leaving others undefined. **Pros and Cons of Each Approach** Here are the pros and cons for each approach: * **Native Destructure**: * Pros: Native destructuring is generally faster since it doesn't involve additional function calls or library overhead. * Cons: It can be less readable and might require more complex code, especially when dealing with nested objects. * **LoDash Omit**: * Pros: LoDash's `omit` function provides a clear and concise way to remove properties from an object. It also offers flexibility through the use of arrays for specified properties. * Cons: Since it involves calling another library, there might be slight performance penalties compared to native destructuring or Object.assign. * **LoDash Pick**: * Pros: LoDash's `pick` function gives a simple way to keep only specific properties from the base palette. It is also easier to read than using filter() along with object comprehension. * Cons: Similar to LoDash Omit, it uses another library and might incur additional overhead due to function calls. **Library Considerations** The benchmark uses LoDash (a utility library) for its `omit` and `pick` functions. This means that any performance differences between these approaches can be attributed to the use of this external library versus native JavaScript features like destructuring or Object.assign. **Other Alternatives** Some alternative methods you might consider include: * Using ES6 object comprehension (Object.fromEntries() and Object.entries()) to achieve similar results. * Applying the `delete` operator on each property individually, which could provide a performance boost due to less function call overhead but may also increase code complexity. In summary, the choice of approach largely depends on your specific requirements, personal preference for readability vs. speed, and whether you're willing or able to handle potential additional complexities in your chosen method.
Related benchmarks:
Native Undefined vs Lodash isUndefined
Lodash omit vs Native object destruction
Plain js vs OmitBy
Plain js vs OmitBy(2)
Comments
Confirm delete:
Do you really want to delete benchmark?