Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
_.pickBy vs native
(version: 0)
Comparing performance of:
_.pickBy vs native vs soy
Created:
6 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);
native
Object.entries(obj).reduce((acc, [k, v]) => { if (predicate(v)) acc[k] = v; return acc; }, {});
soy
Object.fromEntries(Object.entries(obj).filter(([k, v]) => predicate(v)));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
_.pickBy
native
soy
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
6 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36
Browser/OS:
Chrome 141 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.pickBy
29177.9 Ops/sec
native
36651.1 Ops/sec
soy
23469.3 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what's being tested. **Benchmark Overview** The benchmark measures the performance of three approaches to filter an object: `_.pickBy` from Lodash, the native JavaScript approach using `Object.entries`, and another alternative called "soy". **Script Preparation Code** The script preparation code creates a large array of 1000 objects with unique indices. Each object has a value that can be either even or odd. ```javascript var obj = Array(1000) .fill() .reduce((acc, curr, i) => { acc[i] = i; return acc; }, {}); var predicate = v => v % 2 === 0; ``` The `predicate` function is used to filter the objects based on whether their value is even. **Html Preparation Code** The HTML preparation code includes a reference to Lodash, which is required for the `.pickBy` approach. ```html <script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script> ``` **Individual Test Cases** There are three test cases: 1. `_.pickBy`: This test case uses Lodash's `pickBy` function to filter the object based on the predicate. 2. `native`: This test case uses the native JavaScript approach using `Object.entries` and `filter`. 3. `soy`: This test case uses another alternative approach called "soy", which is not a widely known or maintained library. **What's being compared?** The benchmark compares the performance of three approaches to filter an object: * `.pickBy` from Lodash * The native JavaScript approach using `Object.entries` and `filter` * Another alternative approach called "soy" (which is not well-known or maintained) **Pros and Cons of each approach:** 1. `.pickBy` (Lodash): * Pros: + Convenient and concise syntax + Works with other Lodash functions for chaining * Cons: + Additional dependency on Lodash + May have a higher overhead due to the library 2. Native JavaScript: * Pros: + No additional dependencies or overhead + Optimized for performance * Cons: + More verbose syntax + Requires understanding of JavaScript array methods 3. Soy (alternative approach): * Not enough information is available about this approach, and it's not clear what its performance characteristics are. **Other considerations:** * The benchmark measures the execution speed, but does not consider other factors such as memory usage or cache behavior. * The use of a large array with 1000 objects may be too small for a representative test case. A larger dataset might provide more accurate results. * The benchmark only tests filtering an object based on a predicate. Other filtering scenarios, such as filtering by multiple conditions or using other data structures (e.g., Maps), are not tested. **Alternatives:** If you're looking for alternative approaches to filter objects in JavaScript, here are some options: * Using `Array.prototype.filter()` method * Using `Object.keys()` and `reduce()` * Using `Map` data structure with the `get()` method Keep in mind that each approach has its own trade-offs, and the choice of which one to use depends on your specific requirements and performance constraints.
Related benchmarks:
_.pickBy vs native vs plain old code
_.pickBy vs filter on array
_.pickBy vs _.filter on array
_.pickBy vs native more data
_.pickBy vs native Object.entries + filter
Comments
Confirm delete:
Do you really want to delete benchmark?