Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
R vs _
(version: 0)
Comparing performance of:
R.pick vs _.pick
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/ramda@0.26.1/dist/ramda.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/lodash@4.17.11/lodash.fp.min.js"></script>
Script Preparation code:
var obj = { _id: 'aCfb6SsPigZQSd6Cl4Bzh', email: 'eblo.s.ushami@gmail.com', firstName: 'Ебло с ушами', patronymic: 'Ильинична', gender: 'female', createdAt: '2019-10-14T13:32:35.458Z', updatedAt: '2019-10-14T13:32:35.458Z', __v: 0 } var pickFields = [ 'email', 'phone', 'firstName', 'lastName', 'patronymic', 'gender', 'dateOfBirth' ]
Tests:
R.pick
R.pick(pickFields, obj)
_.pick
_.pick(obj, pickFields)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
R.pick
_.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 dive into the world of JavaScript microbenchmarks! **What is tested?** The provided benchmark tests two different approaches to pick specific fields from an object using functional programming. In this case, we have: 1. `R.pick(pickFields, obj)`: This uses the Ramda library, a popular functional programming library for JavaScript. 2. `_.pick(obj, pickFields)`: This uses the Lodash library, another widely-used utility library for JavaScript. **What options are compared?** The two options being tested are: 1. **Ramda's `pick` function**: This function takes two arguments: an array of field names (`pickFields`) and an object (`obj`). It returns a new object with only the specified fields. 2. **Lodash's `_pick` function**: Similar to Ramda's `pick`, but part of Lodash. **Pros and Cons** Here are some general pros and cons for each approach: **Ramda's `pick` function:** Pros: * Highly optimized and efficient, thanks to its functional programming nature. * Provides a simple and concise API for picking fields from an object. * Well-documented and widely adopted in the JavaScript community. Cons: * Requires an external library (Ramda) to be included. * May have a slightly higher overhead due to the need to import an additional library. **Lodash's `_pick` function:** Pros: * Part of Lodash, so no additional library needs to be included. * Often considered more "JavaScript-y" and familiar for developers already using Lodash. * Still highly optimized and efficient. Cons: * May not be as concise or elegant in its API compared to Ramda's `pick`. * Has a slightly larger overhead due to the inclusion of the entire Lodash library. **Other considerations** Both functions use a similar pattern: passing an array of field names and an object, with the function returning a new object containing only the specified fields. This makes them relatively straightforward to understand and compare. It's worth noting that both `R.pick` and `_pick` are generally faster than using vanilla JavaScript methods like `Object.assign()` or `Object.keys()`, especially for larger objects with many fields. **Library descriptions** * Ramda: A functional programming library for JavaScript, providing a set of higher-order functions to manipulate data in a concise and expressive way. * Lodash: A utility library for JavaScript, providing a comprehensive set of functions for working with arrays, objects, strings, numbers, and more. `_pick` is part of the Lodash "FP" (Functional Programming) module. **Special JS features or syntax** None are mentioned in this benchmark definition. **Other alternatives** If you don't want to use external libraries like Ramda or Lodash, you can also implement `pick`-like functionality using vanilla JavaScript. One common approach is to use the `Object.fromEntries()` method and filtering on an array of field names: ```javascript const pick = (fields, obj) => Object.fromEntries( fields.map(field => [field, obj[field]]) ); ``` This implementation can be more concise but may have slightly higher overhead due to the need for explicit looping.
Related benchmarks:
lodash _filter vs native filter
reduce and sort (native vs lodash)
filter uniq
taetas
Comments
Confirm delete:
Do you really want to delete benchmark?