Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
_.filter vs array filter
(version: 0)
Comparing performance of:
_.filter vs array filter
Created:
7 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.core.js"></script>
Script Preparation code:
var numbers = [10, 40, 230, 15, 18, 51, 1221]
Tests:
_.filter
_.filter(numbers, num => num % 3 === 0)
array filter
numbers.filter(num => num % 3 === 0)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.filter
array filter
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Browser/OS:
Chrome 133 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.filter
17537600.0 Ops/sec
array filter
52649124.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON and explain what's being tested. **Benchmark Definition:** The benchmark is comparing two approaches to filter an array of numbers: using Lodash's `_filter` function and using JavaScript's built-in `filter` method. **Script Preparation Code:** This code snippet defines a variable `numbers` which is an array of integers: ```javascript var numbers = [10, 40, 230, 15, 18, 51, 1221]; ``` **Html Preparation Code:** This line includes the Lodash library from a CDN: ```html <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.core.js"></script> ``` **Individual Test Cases:** There are two test cases: 1. `_.filter(numbers, num => num % 3 === 0)`: This line calls the `_filter` function from Lodash on the `numbers` array, filtering out numbers that are not divisible by 3. 2. `numbers.filter(num => num % 3 === 0)`: This line uses JavaScript's built-in `filter` method to achieve the same result as the previous test case. **Pros and Cons of Each Approach:** 1. **Lodash's `_filter` function:** * Pros: + More concise and readable code + Lodash provides a well-maintained and widely-used library for functional programming utilities * Cons: + Requires an external library to be included, which may add overhead + May not be the most optimal solution for small arrays or simple filtering tasks 2. **JavaScript's built-in `filter` method:** * Pros: + No additional libraries required, making it a lightweight option + Built into the language, so no external dependencies to worry about * Cons: + May require more code to achieve the same result as Lodash's `_filter` + Less readable or maintainable for complex filtering tasks **Other Considerations:** * The benchmark assumes that both functions will be used with a similar input size and complexity. * The use of Lodash's `_filter` function may provide additional benefits, such as caching and memoization, which are not present in the JavaScript `filter` method. **Special JS Features/Syntax:** None mentioned. However, it's worth noting that the benchmark is using ES6-style arrow functions (`num => num % 3 === 0`) for simplicity and readability. **Library Used:** Lodash (version 4.17.11) provides the `_filter` function used in the first test case. **Device/Platform Considerations:** The benchmark result includes data from a Chrome 131 browser running on a Mac OS X 10.15.7 device, which is an example of the specific device/platform being tested.
Related benchmarks:
Array.prototype.filter vs Lodash filter
Array.prototype.filter vs Lodash filter (Even Numbers)
Array.prototype.filter vs Lodash 4.17.5 filter
Speed Test : _.filter vs array filter
Comments
Confirm delete:
Do you really want to delete benchmark?