Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
_.pickBy vs filter on array
(version: 0)
Comparing performance of:
_.pickBy vs filter
Created:
4 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 obj = Array(1000) .fill() .reduce((acc, curr, i) => { acc[i] = i; return acc; }, []); var predicate = v => v % 2 === 0;
Tests:
_.pickBy
_.pickBy(obj, predicate);
filter
obj.filter(e => predicate(e))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.pickBy
filter
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36
Browser/OS:
Chrome 147 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.pickBy
6595.0 Ops/sec
filter
241787.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON data and explain what's being tested. **Benchmark Definition** The benchmark measures the performance difference between two JavaScript functions: `_.pickBy` from Lodash and `filter` (built-in array method). **Script Preparation Code** The script creates an array of 1000 elements, where each element is assigned a unique index using the `reduce` method. This array will be used as the input data for both benchmark tests. ```javascript var obj = Array(1000) .fill() .reduce((acc, curr, i) => { acc[i] = i; return acc; }, []); ``` **Html Preparation Code** The HTML code includes a script tag that loads the Lodash library version 4.17.5. ```html <script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script> ``` **Benchmark Test Cases** There are two test cases: 1. `_.pickBy(obj, predicate)` 2. `obj.filter(e => predicate(e))` These test cases compare the performance of the `_.pickBy` function from Lodash and the built-in `filter` method. **Options Compared** The benchmark tests the following options: * `_._pickBy`: A function from the Lodash library that creates a new array with only the elements for which the predicate returns true. * `filter`: A built-in array method that creates a new array with only the elements for which the callback function returns true. **Pros and Cons of Each Approach** 1. **_.pickBy` (Lodash)**: * Pros: Often more concise and readable, especially for complex predicates or when working with large datasets. * Cons: Adds external dependency on Lodash, may have slower startup times due to lazy loading. 2. **filter** (built-in): * Pros: Fastest option, as it's a built-in method that doesn't require any additional libraries. * Cons: May be less readable or more verbose for complex predicates. **Library: Lodash** Lodash is a popular JavaScript utility library that provides various functions to simplify common programming tasks. In this case, the `_pickBy` function creates a new array with filtered elements, making it an efficient and concise solution for filtering arrays. **Special JS Feature/Syntax** There are no special features or syntaxes used in these benchmark tests. They rely on standard JavaScript syntax and built-in methods. **Alternatives** Other alternatives to `_.pickBy` include: * Using a custom filter function with the `Array.prototype.filter()` method. * Using a library like Ramda, which provides a similar `_pickBy` function with various options for filtering arrays. In summary, the benchmark measures the performance difference between the Lodash `_pickBy` function and the built-in `filter` method in JavaScript. It tests these two approaches on an array of 1000 elements to determine which one is faster and more efficient.
Related benchmarks:
_.pickBy vs native vs plain old code
_.pickBy vs _.filter on array
_.pickBy vs native Object.entries + filter
_pickBy vs native Object.entries + filter
Comments
Confirm delete:
Do you really want to delete benchmark?