Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
_.pickBy vs native Object.entries + filter
(version: 0)
Comparing performance of: _.pickBy() vs Object.entries().filter()
Comparing performance of:
_.pickBy vs native filter
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 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 filter
Object.entries(obj).filter(predicate)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.pickBy
native filter
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_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36
Browser/OS:
Chrome 129 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.pickBy
30055.9 Ops/sec
native filter
6217.7 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of performance benchmarking with MeasureThat.net. **Benchmark Definition** The provided JSON represents a benchmark that compares the performance of two approaches: Lodash's `_.pickBy()` function and native JavaScript's `Object.entries().filter()` method. The benchmark is designed to measure the speed of each approach in extracting specific properties from an object based on a predicate function. **Options Compared** Two options are compared: 1. **Lodash's `_pickBy()` function**: This function takes two arguments, `object` and `predicate`, where `object` is the source object, and `predicate` is a function that returns `true` for the desired properties. The function iterates through the properties of the object using a `for...in` loop and includes only the properties for which the predicate function returns `true`. 2. **Native JavaScript's `Object.entries().filter()` method**: This approach uses the `entries()` method to iterate over an object's key-value pairs, converting it into an array of arrays. The `filter()` method is then applied to this array, allowing you to specify a callback function that filters out unwanted properties. **Pros and Cons** Here are some pros and cons for each approach: * **Lodash's `_pickBy()` function**: + Pros: Easy to use, concise syntax, fast performance due to optimized internal implementation. + Cons: Requires an additional library (Lodash) to be included in the benchmark script, can be slower than native JavaScript implementations if not used efficiently. * **Native JavaScript's `Object.entries().filter()` method**: + Pros: Fast performance, does not require an additional library, and is a standard part of modern JavaScript engines. + Cons: Can be slower for very large objects due to the overhead of creating arrays from object entries, may have higher memory usage. **Library and Syntax Considerations** In this benchmark, Lodash's `_.pickBy()` function is used. The `_pickBy` method is a utility function in Lodash that extracts specific properties from an object based on a predicate function. This library provides additional utility functions for array and object manipulation, among others. There are no special JavaScript features or syntax used in this benchmark. It relies solely on standard JavaScript language features. **Alternatives** For native JavaScript implementations, you can also use other approaches like: * Using `Object.keys()` to get an array of keys, then using `Array.prototype.filter()` to filter out unwanted properties. * Using `Object.getOwnPropertyNames()` or `Object.getOwnPropertySymbols()` (depending on the object type) to iterate over object properties directly. Keep in mind that each approach has its own performance characteristics and trade-offs. MeasureThat.net helps you compare these different methods under controlled conditions, allowing for a more accurate assessment of their relative performance.
Related benchmarks:
Array.prototype.filter vs Lodash filter
Array.prototype.filter vs Lodash without
Array.prototype.filter vs Lodash without 2
Array.prototype.filter vs Lodash filter bumped to 10k
Array.prototype.filter vs Lodash filter for ~10000
Comments
Confirm delete:
Do you really want to delete benchmark?