Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
compare filter with lodash methods
(version: 0)
compare filter with lodash methods
Comparing performance of:
Native .filter vs Lodash pull
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"></script>
Script Preparation code:
var indexes = [1, 3, 5, 7, 8, 12, 13];
Tests:
Native .filter
indexes.filter(x => x !== 7);
Lodash pull
_.pull(indexes, 7);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Native .filter
Lodash pull
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36
Browser/OS:
Chrome 123 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native .filter
13064329.0 Ops/sec
Lodash pull
5271459.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down what's being tested in the provided JSON benchmark. **What is being tested?** The test compares the performance of two approaches to filter an array: native JavaScript `.filter()` method and Lodash's `_.pull()` method. **Options compared:** 1. Native JavaScript `.filter()` 2. Lodash's `_.pull()` method **Pros and Cons:** * **Native JavaScript `.filter()`**: This approach is built-in to JavaScript, so it doesn't require any additional libraries or overhead. However, it may not be as optimized as other approaches. Additionally, the performance of this approach can vary depending on the browser and version used. * **Lodash's `_.pull()` method**: Lodash is a popular utility library for JavaScript that provides various functional programming helpers. Using `_.pull()` eliminates the need to create a new array with filtered elements, which can be beneficial in terms of memory efficiency. However, it requires an additional dependency and may introduce some overhead due to the size of the Lodash library. **Library used:** In this case, the test uses Lodash version 4.17.21, which is a relatively stable and widely-used version at the time of writing. **Special JS feature or syntax:** There are no special JavaScript features or syntax mentioned in the provided benchmark code. It's a straightforward comparison of two array filtering methods. **Other alternatives:** If you want to compare other array filtering methods, here are some alternatives: * **Array.prototype.filter() with a custom function**: Instead of using Lodash's `_.pull()` method, you can create your own custom function that uses the native JavaScript `.filter()` method to achieve similar results. * **Underscore.js functions (e.g., _.difference())**: If you prefer to use another utility library, you can use Underscore.js functions like `_difference()` or other filtering helpers to compare their performance with Lodash's `_.pull()` method. **Benchmark preparation code:** The provided "Script Preparation Code" sets up an array of numbers (`indexes`) that will be used for filtering. The "Html Preparation Code" loads the Lodash library from a CDN, making it available for use in the benchmark. By comparing these two array filtering methods, MeasureThat.net can help users understand the performance characteristics of each approach and choose the best one for their specific use cases.
Related benchmarks:
_.filter vs array filter
Array.prototype.filter vs Lodash 4.17.5 filter
Speed Test : _.filter vs array filter
Lodash - uniq2
Comments
Confirm delete:
Do you really want to delete benchmark?