Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash Pick vs Native destructuring vs Manual
(version: 0)
Compare _.pick vs native destructuring
Comparing performance of:
Lodash vs Native vs Manual pick
Created:
6 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 <= 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
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
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; });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Lodash
Native
Manual pick
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
4 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:146.0) Gecko/20100101 Firefox/146.0
Browser/OS:
Firefox 146 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash
4.3 Ops/sec
Native
497.4 Ops/sec
Manual pick
29.3 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview** The provided JSON represents a benchmarking test for comparing the performance of three approaches to extract specific properties from an object in JavaScript: Lodash's `pick` function, native destructuring, and manual property extraction. **Benchmark Definition** The benchmark definition consists of three individual test cases: 1. **Lodash**: Uses Lodash's `pick` function to extract specific properties from the object. 2. **Native**: Utilizes native destructuring syntax to extract properties from the object. 3. **Manual pick**: Manually extracts properties using a loop and the `in` operator. **Options Compared** The three approaches are compared in terms of their performance, which is measured by the number of executions per second on a given test case (arr.map function). **Pros and Cons** 1. **Lodash (`pick` function)**: * Pros: Lodash provides a convenient and flexible way to extract properties from objects. * Cons: It may introduce additional overhead due to the library's execution time. 2. **Native destructuring**: * Pros: Native destructuring is fast, concise, and widely supported in modern browsers. * Cons: May require more cognitive load for developers unfamiliar with this syntax. 3. **Manual pick (loop)**: * Pros: Manually extracting properties using a loop can be efficient and easy to understand for some developers. * Cons: Can be time-consuming and error-prone, especially for large objects. **Library and Purpose** The Lodash library is used in the "Lodash" test case. Its primary purpose is to provide a set of functional programming helpers, including the `pick` function. **Special JS Feature or Syntax** Native destructuring syntax (e.g., `{ type, subtype, ... } = element;`) is used in the "Native" test case. This feature allows developers to extract multiple properties from an object into separate variables in a single statement. **Other Alternatives** If native destructuring is not supported by older browsers or environments, alternative approaches can be considered: * Using `Object.keys()` and `Array.prototype.map()` * Employing a library like underscore (not Lodash) or moment.js * Utilizing other JavaScript object manipulation techniques Please note that the performance differences between these approaches may vary depending on the specific use case, browser versions, and system configurations. I hope this explanation helps you understand the benchmarking test and the pros and cons of each approach!
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 Picks 1M
Comments
Confirm delete:
Do you really want to delete benchmark?