Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash.filter vs Lodash.without vs array.filter
(version: 0)
Comparing performance of:
filter vs without vs array.filter
Created:
2 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 arr = Array.from(Array(100000).keys())
Tests:
filter
_.filter(arr, o => o !== 99999);
without
_.without(arr, 99999);
array.filter
arr.filter(o => o !== 99999);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
filter
without
array.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):
Let's break down the benchmark and explain what's being tested, compared, and the pros and cons of each approach. **Benchmark Overview** The benchmark compares three approaches to filter an array in JavaScript: 1. `_.filter` (Lodash) 2. `_.without` (Lodash) 3. `array.filter` (native JavaScript) **Comparison of Approaches** ### 1. Lodash _.filter * Purpose: Filter elements from an array based on a provided function. * Code example: `_.filter(arr, o => o !== 99999)` * Library: Lodash is a popular utility library for JavaScript. Pros: * Convenient and concise syntax * Often provides additional features and optimizations out of the box (e.g., handling null/undefined values) Cons: * Adds extra overhead due to the library's dependencies and optimizations. * May not be as efficient as native JavaScript for simple filtering operations. ### 2. Lodash _.without * Purpose: Remove elements from an array by their presence in another array or value. * Code example: `_.without(arr, 99999)` * Library: Lodash is a popular utility library for JavaScript. Pros: * Similar to `_.filter`, but with a different approach and syntax. * May be optimized differently than `_.filter` due to the underlying algorithm used. Cons: * Adds extra overhead due to the library's dependencies and optimizations, similar to `_filter`. ### 3. array.filter (native JavaScript) * Purpose: Filter elements from an array based on a provided function. * Code example: `arr.filter(o => o !== 99999)` * No external libraries required. Pros: * Lightweight and efficient, with minimal overhead. * Optimized for performance by being native to JavaScript. Cons: * Requires more verbose syntax compared to Lodash functions. * May not provide additional features or optimizations out of the box. **Test Results** The latest benchmark results show that: * `_.without` performed best with an average execution rate of 1153.4171142578125 executions per second on Firefox 119. * `array.filter` performed closest to `_.without`, with an average execution rate of 1148.49462890625 executions per second on the same browser and device platform. The results suggest that both Lodash functions provide similar performance, while the native JavaScript `array.filter` approach is slightly less efficient but still relatively fast. **Other Alternatives** For filtering arrays in JavaScript, other approaches exist: * Using `Array.prototype.filter()` (native JavaScript): Similar to `array.filter`, but with a more concise syntax. * Using `filter()` from `underscore.js`: Another utility library that provides an alternative implementation of the filtering algorithm. * Implementing your own custom filtering function using a simple loop or recursive approach. Keep in mind that performance differences between these approaches may vary depending on specific use cases and requirements.
Related benchmarks:
Array.prototype.filter vs Lodash filter
Array.prototype.filter vs Lodash filter
Array.prototype.filter vs Lodash 4.17.5 filter
Lodash.filter vs Lodash.without
Comments
Confirm delete:
Do you really want to delete benchmark?