Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash omit vs Native destructuring vs Manual omit 2022
(version: 0)
Compare _.omit vs native destructuring vs manual omit
Comparing performance of:
Lodash vs Native vs Manual omit
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"></script>
Script Preparation code:
var arr = []; var object = { type: 'aaa', subtype: 'bbb', card_last4:'bbb', card_type:'bbb', card_exp_month:'bbb', card_exp_year:'bbb', card_country:'bbb', foo: 'bar' }; for (var i = 0; i <= 100000; i++) { arr.push(object); }
Tests:
Lodash
arr.map(function (element) { return _.omit( element, 'card_last4', 'card_type', ); });
Native
arr.map(function (element) { const { card_last4, card_type, ...rest } = element; return rest; });
Manual omit
arr.map(function (element) { return { type: element.type, subtype: element.subtype, card_exp_month: element.card_exp_month, card_exp_year: element.card_exp_year, card_country: element.card_country, something: element.something }; });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Lodash
Native
Manual omit
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):
Let's dive into the world of JavaScript microbenchmarks. **Benchmark Definition** The benchmark is designed to compare three approaches: 1. **Lodash**: A popular JavaScript utility library that provides various functions, including `omit`, for working with objects. 2. **Native Destructuring**: The native JavaScript syntax for destructuring objects, which allows us to extract specific properties from an object while ignoring others. 3. **Manual Omit**: A custom approach where we create a new object with only the desired properties. **Options Compared** We're comparing the performance of each approach on a large dataset of 100,000 objects. The benchmark measures the time it takes to execute each approach using the `map` function on this dataset. **Pros and Cons of Each Approach** 1. **Lodash**: Pros: * Convenient and easy to use. * Provides a well-maintained and widely adopted library for common tasks. Cons: * Introduces additional overhead due to the library's functionality and parsing. 2. **Native Destructuring**: Pros: * Native to JavaScript, so no additional overhead from a library. * Efficient and concise syntax. Cons: * Requires a basic understanding of destructuring syntax, which might not be familiar to all developers. 3. **Manual Omit**: Pros: * No external dependencies or overhead. * Allows for customization and control over the resulting object structure. Cons: * More verbose and requires manual handling of property names. **Library - Lodash** Lodash is a popular JavaScript utility library that provides various functions, including `omit`, for working with objects. The `omit` function takes two arguments: the object to be modified and an object containing properties to remove from the original object. In this benchmark, we're using the `lodash.min.js` file from a CDN. **Special JS Feature/Syntax - Native Destructuring** Native destructuring is a syntax feature introduced in ECMAScript 2018 (ES10) that allows us to extract specific properties from an object while ignoring others. The syntax is similar to array destructuring, but applied to objects. In this benchmark, we're using native destructuring with the `const` declaration and rest parameter (`...rest`) to achieve a similar effect to Lodash's `omit` function. **Benchmark Preparation Code** The script preparation code creates an empty array `arr` and an object `object` with various properties, including some that we want to omit in the benchmark. The code then pushes this object 100,000 times into the `arr` array using a loop. **Html Preparation Code** The HTML preparation code includes a script tag pointing to Lodash's CDN file, which is used by the benchmark. **Other Alternatives** If you're interested in exploring alternative approaches or testing other libraries, here are some options: 1. **ES6 Object Rest Syntax**: This syntax allows us to extract properties from an object while ignoring others using the rest parameter (`...rest`) and destructuring assignment (`{ ...rest }`). 2. **JSON Path**: A library that provides a way to query and manipulate JSON data, which could be used as an alternative to Lodash's `omit`. 3. **Other JavaScript libraries or frameworks**: Depending on your specific use case, you might find other libraries or frameworks that offer similar functionality to Lodash's `omit`, such as Ramda, Moment.js, or React. Keep in mind that each approach has its pros and cons, and the choice of which one to use depends on your specific requirements and performance constraints.
Related benchmarks:
Lodash.js versus Native
lodash remove vs native filter
Lodash reduce vs transform vs Native reduce on object (Object without prototype)
Lodash difference vs Set & Filter vs Map
Lodash deepMerge vs Object.assign
Comments
Confirm delete:
Do you really want to delete benchmark?