Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash pick and native method 2
(version: 0)
Comparing performance of:
Lodash pick vs Native pick
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
var arr = []; var object = { type: 'aaa', foo: 'bar' }; for (var i = 0; i <= 10; i++) { arr.push(object); }
Tests:
Lodash pick
arr.map(function (element) { return _.pick( element, 'type', 'subtype', 'card_last4', 'card_type', 'card_exp_month', 'card_exp_year', 'card_country', 'something' ); });
Native pick
function pick(object, keys) { return keys.reduce((obj, key) => { if (object && object.hasOwnProperty(key)) { obj[key] = object[key]; } return obj; }, {}); } arr.map(function (element) { return pick( element, ['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 pick
Native pick
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:136.0) Gecko/20100101 Firefox/136.0
Browser/OS:
Firefox 136 on Mac OS X 10.15
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash pick
151499.4 Ops/sec
Native pick
2593924.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Measuring performance is an essential task in software development, and MeasureThat.net provides a great platform for testing JavaScript microbenchmarks. **Overview of the Benchmark** The benchmark measures the performance difference between two approaches: using Lodash's `pick` function and implementing a custom `pick` function using only native JavaScript. **Lodash's `pick` Function** Lodash is a popular JavaScript utility library that provides various functions for tasks such as array manipulation, object creation, and more. The `pick` function in Lodash takes an object and an array of keys as arguments and returns a new object containing only the specified key-value pairs. **Native Pick Function** The native pick function uses only native JavaScript to achieve the same result as Lodash's `pick` function. It iterates through the provided array of keys, checks if each key exists in the input object, and adds it to the output object if it does. **Comparison of Approaches** Here are some pros and cons of each approach: * **Lodash's `pick` Function:** + Pros: - Faster execution time due to optimized native code. - Easier to use and more readable syntax. - Supports multiple platforms and browsers out-of-the-box. + Cons: - Requires an additional library (Lodash) to be included in the project. - May have dependencies or conflicts with other libraries. * **Native Pick Function:** + Pros: - Faster execution time due to native code optimizations. - No external dependencies or libraries required. - Allows for more control over implementation details. + Cons: - More complex syntax and harder to read. - May have platform-specific issues or compatibility problems. **Other Considerations** When choosing between these approaches, consider the following factors: * **Performance**: If speed is a top priority, the native pick function might be a better choice. However, if you're working on a project with existing Lodash dependencies and don't need extreme performance optimization, using Lodash's `pick` function might be sufficient. * **Readability and Maintainability**: For more complex projects or collaborative development environments, using Lodash's `pick` function can improve code readability and maintainability. * **Platform and Browser Support**: If you're targeting multiple platforms or browsers, Lodash's `pick` function provides a convenient way to handle these differences. **Library and Syntax Details** Lodash is a popular JavaScript utility library that provides various functions for tasks such as array manipulation, object creation, and more. The `pick` function in Lodash takes an object and an array of keys as arguments and returns a new object containing only the specified key-value pairs. The native pick function uses a similar syntax to Lodash's `pick` function but relies on native JavaScript to achieve the same result.
Related benchmarks:
native vs lodash
Spread Operator vs Lodash with not so many items
lodash flatten vs native flat with nested objects
Array From vs lodash clone
Comments
Confirm delete:
Do you really want to delete benchmark?