Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash Pick vs Native destructuring vs Manual Picks 1M
(version: 0)
Compare _.pick vs native destructuring vs manual picks
Comparing performance of:
Lodash vs Native vs Manual pick with property names vs Manual pick
Created:
3 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.11/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 <= 1000000; i++) { arr.push(object); }
Tests:
Lodash
arr.map(function (element) { return _.pick( element, 'type', 'subtype', 'card_last4', 'card_type', 'card_exp_month', 'card_exp_year', 'card_country', 'something' ); });
Native
arr.map(function (element) { const { type, subtype, card_last4, card_type, card_exp_month, card_exp_year, card_country, something } = element; return { type, subtype, card_last4, card_type, card_exp_month, card_exp_year, card_country, something }; });
Manual pick with property names
const props = [ "type", "subtype", "card_last4", "card_type", "card_exp_month", "card_exp_year", "card_country", "something" ]; arr.map(function (element) { const res = {}; for(let prop of props){ res[prop] = element[prop] } return res; });
Manual pick
arr.map(function (element) { return { type: element.type, subtype: element.subtype, card_last4: element.card_last4, card_type: element.card_type, 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 (4)
Previous results
Fork
Test case name
Result
Lodash
Native
Manual pick with property names
Manual pick
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 break down the benchmark and explain what's being tested. **What is being tested?** The benchmark is comparing three approaches to extract specific properties from an object: 1. **Lodash `pick` method**: This uses the Lodash library to selectively extract properties from an object. 2. **Native destructuring**: This uses JavaScript's native syntax to destructure the object and extract the desired properties. 3. **Manual picks with property names**: This manually iterates over a list of property names to extract the corresponding values from the object. **Options compared** The three options are being compared for their performance in extracting specific properties from an object. **Pros and cons of each approach:** * **Lodash `pick` method**: + Pros: Convenient, easy to use, and well-tested. + Cons: Requires additional library dependency (Lodash), may have overhead due to library initialization. * **Native destructuring**: + Pros: Fast, efficient, and native to JavaScript. + Cons: Limited flexibility in terms of property selection, requires understanding of destructure syntax. * **Manual picks with property names**: + Pros: Flexible, easy to customize, and does not require additional libraries. + Cons: May be slower due to manual iteration, requires more code and maintenance. **Library usage** The benchmark uses the Lodash library for its `pick` method. Lodash is a popular utility library that provides a wide range of functions for working with JavaScript objects, arrays, and more. **Special JS feature or syntax** There is no special JavaScript feature or syntax used in this benchmark. The focus is on comparing different approaches to extract properties from an object. **Other alternatives** If you're interested in exploring alternative approaches, here are a few: * **Using `Object.assign()`**: This method can be used to create a new object with specific properties extracted from the original object. * **Using a loop and conditional statements**: Similar to manual picks with property names, this approach involves iterating over an array of property names and assigning corresponding values to a new object. * **Using a library like `lodash` for its other utility functions**: Lodash provides many other useful functions beyond just `pick`, such as `map()`, `filter()`, and more. Keep in mind that the performance difference between these approaches may not be significant, especially for small to medium-sized objects. However, if you need to work with large datasets or require high performance, optimizing this step can make a noticeable impact.
Related benchmarks:
Lodash Pick vs Native destructuring vs Manual Picks
Lodash Pick vs Native destructuring vs Manual Picks vs pick fn
Lodash Pick vs Native destructuring vs Manual Picks vs Delete Props
Lodash Pick vs Native destructuring vs Manual Picks1
Comments
Confirm delete:
Do you really want to delete benchmark?