Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
filter vs _without (v2)
(version: 0)
Comparing performance of:
filter vs _without vs filter clear vs _without clear vs check length
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 array = [...Array(100000).keys()]; var DEPRECATED = [98100]; var CLEAR_DEPRECATED = [];
Tests:
filter
array.filter(n => DEPRECATED.includes(n));
_without
_.without(array, ...DEPRECATED);
filter clear
array.filter(n => CLEAR_DEPRECATED.includes(n));
_without clear
_.without(array, ...CLEAR_DEPRECATED);
check length
if(CLEAR_DEPRECATED.length){ _.without(array, ...CLEAR_DEPRECATED); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
filter
_without
filter clear
_without clear
check length
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/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
filter
1549.8 Ops/sec
_without
2465.3 Ops/sec
filter clear
1636.5 Ops/sec
_without clear
3633.5 Ops/sec
check length
112220936.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and analyze what's being tested. **Benchmark Overview** The benchmark compares the performance of three approaches to filter out elements from an array: 1. `Array.prototype.filter()` 2. `_without()` function from Lodash library 3. Conditional check with `_without()` when a specific condition is met **Options Compared** Here are the options being compared, along with their pros and cons: ### 1. `Array.prototype.filter()` * **Pros:** Simple and intuitive syntax, widely supported by browsers. * **Cons:** May have poor performance for large datasets due to the overhead of the `filter()` method. ### 2. `_without()` function from Lodash library * **Pros:** Optimized for performance, especially when dealing with large arrays. Also provides a concise syntax. * **Cons:** Requires an external library (Lodash) which may not be included in all projects. **Other Considerations** In addition to the above options, there's also a conditional check using `_without()`: ```javascript if(CLEAR_DEPRECATED.length){\r\n _.without(array, ...CLEAR_DEPRECATED);\r\n} ``` This approach has the same pros and cons as `_without()`, but with an added layer of complexity due to the conditional statement. **Lodash Library** The `_without()` function is part of the Lodash library, which provides a collection of useful functions for functional programming. In this benchmark, Lodash is included in the HTML preparation code using a script tag. **JavaScript Features/Syntax** None of the above options rely on any special JavaScript features or syntax beyond what's supported by modern browsers. **Other Alternatives** If you're looking for alternative approaches to filtering arrays, some other options include: * Using `Array.prototype.every()` and `Array.prototype.some()` * Utilizing libraries like `p-queue` or `fast-filter` which are optimized for performance * Implementing a custom filtering function using iteration Keep in mind that the best approach will depend on your specific use case and requirements.
Related benchmarks:
Array.prototype.filter vs Lodash without
Array.prototype.filter vs Lodash.without
Array.prototype.filter vs Lodash 4.17.5 filter
Array.prototype.filter vs Lodash without 2
Lodash.filter vs Lodash.without vs array.filter
Comments
Confirm delete:
Do you really want to delete benchmark?