Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object.values(...).filter vs. _.filter
(version: 0)
Comparing performance of:
Object.values(...).filter vs _.filter
Created:
5 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 max1 = 100000; // 100,000 (100 Thousand) var max2 = 10000000; // 10,000,000 (10 Million) var max3 = 100000000; // 100,000,000 (100 Million) // Create large arrays var arr1 = []; for (var i = 0; i <= max1; i++) { arr1.push(i); } var arr2 = []; for (var i = 0; i <= max2; i++) { arr2.push(i); } var arr3 = []; for (var i = 0; i <= max3; i++) { arr3.push(i); } // Create dictionaries arr1 = _.keyBy(arr1, (value) => value); arr2 = _.keyBy(arr2, (value) => value); arr3 = _.keyBy(arr3, (value) => value);
Tests:
Object.values(...).filter
Object.values(arr1).filter((value) => value < (max1 / 2))
_.filter
_.filter(arr1, (value) => value < (max1 / 2))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Object.values(...).filter
_.filter
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):
**Benchmark Explanation** The provided benchmark is designed to compare the performance of two JavaScript methods: `Object.values()` followed by `filter()`, and `_` (Lodash) followed by `filter()`. The test case uses large arrays (`arr1`, `arr2`, `arr3`) and dictionaries (created using Lodash's `keyBy()` method) to simulate real-world scenarios. **Options Compared** The two options being compared are: 1. **Object.values().filter()**: This approach involves first extracting the values from an array object using `Object.values()` and then filtering the resulting array using the `filter()` method. 2. **_.filter(arr1, ...) (Lodash)**: This approach uses Lodash's `filter()` function to filter the elements of the `arr1` array directly. **Pros and Cons** * **Object.values().filter()**: + Pros: More explicit and intuitive way to extract values from an array object. + Cons: May have higher overhead due to the extra function call and potential performance impact on larger arrays. * **_.filter(arr1, ...) (Lodash)**: + Pros: More efficient and concise way to filter an array using a popular library like Lodash. + Cons: Requires including the additional library in the test environment, which may not be desirable for all use cases. **Library: _.filter (Lodash)** The `_` library is a JavaScript utility belt that provides various functions for common tasks, such as filtering arrays. In this benchmark, `_.filter()` is used to filter the elements of `arr1`. **Special JS Feature or Syntax** There are no special JavaScript features or syntaxes being tested in this benchmark. **Other Alternatives** If you want to explore alternative approaches, here are a few options: * **Array.prototype.filter()**: This approach would involve using the `filter()` method on the array object itself, rather than extracting values first. * **map() and filter()**: Another approach could be to use the `map()` method to transform the array before filtering it. **Benchmark Preparation Code Analysis** The script preparation code generates three large arrays (`arr1`, `arr2`, `arr3`) and creates dictionaries using Lodash's `keyBy()` method. The arrays are populated with consecutive integers from 0 to `max1` (100,000), `max2` (10,000,000), and `max3` (100,000,000) respectively. The `Object.values(arr1).filter()` and `_.filter(arr1, ...)` expressions are used as the benchmarking code. The resulting arrays are not used in the benchmark; instead, the focus is on measuring the performance of the filtering functions.
Related benchmarks:
Lodash.js vs Native isArrary
Lodash.js vs Native (filter)
Lodash.js vs Native MAGIC
Lodash.js vs Native - filter
Comments
Confirm delete:
Do you really want to delete benchmark?