Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
_.pickBy vs native more data
(version: 0)
Comparing performance of:
_.pickBy vs native vs soy
Created:
3 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(10000) .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:
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! **Benchmark Definition JSON Explanation** The provided JSON represents a benchmark test case created on MeasureThat.net. Here's what it tests: * The `Script Preparation Code` defines a sample object `obj` with 10,000 properties, each initialized with its index. * A predicate function `predicate` is defined to filter even-indexed values from the object. The three benchmark cases are designed to compare different approaches for filtering objects in JavaScript: 1. **_.pickBy (Lodash)**: Uses the Lodash library's `pickBy` function to create a new object with only the filtered properties. 2. **native**: Implements the filtering logic using built-in JavaScript features, creating a new object with only the even-indexed values. 3. **soy**: Utilizes the `Object.fromEntries()` method and filtering an array of key-value pairs to achieve similar results. **Options Compared** The three options are compared in terms of their performance ( executions per second ). The results indicate that: * _.pickBy (Lodash) has a higher execution rate than both native and soy. * **native** performs better than **soy**, which likely due to its simplicity and direct use of built-in methods. **Pros and Cons** Here's a brief summary of the pros and cons of each approach: 1. **_.pickBy (Lodash)**: * Pros: Convenient, easy-to-use function with good performance. * Cons: Requires including an additional library, which might be a drawback for some projects. 2. **native**: * Pros: Simple, efficient, and doesn't require any external libraries. * Cons: May have higher overhead due to the need to create new objects and iterate over key-value pairs. 3. **soy**: * Pros: Similar performance to native but with a more concise implementation. * Cons: Uses `Object.fromEntries()`, which can be slower than direct object creation in some cases. **Library Description** The Lodash library (`lodash.min.js`) is a popular JavaScript utility library that provides a wide range of functional programming helpers, including `pickBy`. It helps to simplify and speed up common tasks like filtering, mapping, and reducing objects. **Special JS Feature/Syntax** No special JavaScript features or syntax are used in this benchmark. However, it's worth noting that some optimizations, like using `Object.fromEntries()` or `Array.prototype.filter()`, rely on specific browser implementations or engine behavior, which can impact performance. **Other Alternatives** If you need to filter objects in JavaScript, other alternatives to _.pickBy include: 1. **Array.prototype.filter()**: Can be used directly on arrays, but requires an array of key-value pairs. 2. **Object.keys(), Object.values(), and Array.prototype.forEach()**: Can be combined with a predicate function to achieve similar results. Keep in mind that these alternatives may have varying performance characteristics depending on the specific use case and browser implementation.
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?