Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash Pick vs Native destructuring
(version: 0)
Compare _.pick vs native destructuring
Comparing performance of:
Lodash vs Native destructing
Created:
3 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', extra: 'extra' }; for (var i = 0; i <= 100000; 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 destructing
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 }; });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash
Native destructing
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 provided JSON data to understand what is being tested in this JavaScript microbenchmark. **Benchmark Definition** The benchmark compares two approaches: using Lodash's `_.pick()` function and native destructuring (also known as ES6 object spread syntax) for selecting specific properties from an object. **Script Preparation Code** The script creates an array of objects, each with several properties, including: * `type` * `subtype` * `card_last4` * `card_type` * `card_exp_month` * `card_exp_year` * `card_country` * `extra` This code is used as the input data for both benchmark tests. **Html Preparation Code** The HTML code includes a script tag that loads Lodash version 4.17.21 from a CDN. This library is used in the first test case (Lodash). **Individual Test Cases** There are two test cases: 1. **Lodash**: The `_.pick()` function is used to select specific properties from each object in the array using an array of keys. For example, `.pick(object, 'type', 'subtype', 'card_last4', ...)`. 2. **Native Destructuring**: This approach uses ES6's object spread syntax to extract specific properties from each object. The `const` statement is used to declare variables for each property, which are then assigned the values using the object's dot notation (e.g., `.type`, `.subtype`, etc.). The extracted properties are then returned as an object. **Pros and Cons of Each Approach** * **Lodash:** + Pros: - Robust and widely used library with a large community - Easy to use for complex data selection tasks + Cons: - Adds extra overhead due to the library's size and complexity - May not be optimized for performance * **Native Destructuring:** + Pros: - Lightweight and efficient, with minimal overhead - Built-in support in modern browsers and Node.js environments + Cons: - Requires understanding of ES6 syntax and object spread - Limited support for complex data selection tasks **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for various tasks, including: * Array manipulation (e.g., `_.map()`, `_ _.filter()`) * Object manipulation (e.g., `_.pick()`, `_.omit()`) * String manipulation (e.g., `_.trim()`, `_ _.toLower()`) Lodash is designed to be flexible and customizable, allowing users to chain methods together for complex operations. **ES6 Syntax** The native destructuring approach uses ES6's object spread syntax, which allows you to extract properties from an object using the following syntax: ```javascript const { property1, property2 } = object; ``` This syntax is used to create a new object with only the selected properties.
Related benchmarks:
Lodash Pick vs Native destructuring vs Manual Picks
Lodash Pick vs Native destructuring vs Manual
Lodash Pick vs Native destructuring vs Manual Picks vs Delete Props
Lodash Pick vs Native destructuring vs Manual Picks 1M
Lodash Pick vs Native destructuring vs Manual Picks1
Comments
Confirm delete:
Do you really want to delete benchmark?