Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Speed Test : _.filter vs array filter
(version: 1)
Comparing performance of:
_.filter vs array filter
Created:
4 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 = [11, 41, 233, 17, 22, 55, 1222, 2444]
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 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Mobile Safari/537.36
Browser/OS:
Chrome Mobile 131 on Android
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.filter
691527.6 Ops/sec
array filter
1656236.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark definition and test cases. **What is tested?** The website MeasureThat.net is running a JavaScript microbenchmark to compare the performance of two approaches: 1. **Array filtering**: `numbers.filter(num => num % 3 === 0)` 2. **Lodash filtering**: `_filter(numbers, num => num % 3 === 0)` Both approaches are used to filter an array of numbers and return only the elements that meet a certain condition (i.e., if the number is divisible by 3). **Options compared** The two options being compared are: * **Array method**: `numbers.filter(num => num % 3 === 0)` * **Lodash method**: `_filter(numbers, num => num % 3 === 0)` Both methods achieve the same result but use different libraries and syntax. **Pros and Cons of each approach** **Array method:** Pros: * Native JavaScript support * Easy to understand and implement Cons: * May not be as efficient as a specialized library like Lodash * Requires manual handling of array iteration and indexing **Lodash method:** Pros: * High-performance implementation optimized for specific use cases * Convenient and concise syntax with `_filter` method * Built-in support for various iteration and filtering algorithms Cons: * Requires an additional library import (`lodash.js`) * May require more learning and adaptation to the Lodash API **Other considerations** * The benchmark uses a simple array of numbers as input, which might not accurately represent real-world scenarios. * There are no variations in input data or conditions being tested, which could limit the relevance of the results. * No comparison is made with other filtering libraries like `Array.prototype.forEach` and `map`. **Library overview** The Lodash library (`lodash.js`) is a popular JavaScript utility library that provides various functions for iterating over arrays, objects, and more. The `_filter` method is one of its features that allows you to filter an array based on a given predicate function. **Special JS feature or syntax** There are no specific JavaScript features or syntax mentioned in the benchmark definition. However, it's worth noting that Lodash methods often rely on ES6+ features like arrow functions (`num => num % 3 === 0`) and template literals (not explicitly used here). **Alternatives** Other filtering libraries or methods could be explored for comparison, such as: * `Array.prototype.forEach` with custom iteration * `map()` function * Other Lodash methods like `_some()`, `_every()`, etc. * Custom JavaScript implementations using loops and bitwise operations Keep in mind that these alternatives would require additional changes to the benchmark definition and script preparation code. I hope this explanation helps software engineers understand what's being tested in this benchmark and provides insights into the pros and cons of different approaches!
Related benchmarks:
_.filter vs array filter
Array.prototype.filter vs Lodash filter (Even Numbers)
Array.prototype.filter vs Lodash 4.17.5 filter
Lodash.filter vs Lodash.without
Comments
Confirm delete:
Do you really want to delete benchmark?