Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash-reject-vs-vanilla-filter
(version: 0)
Comparing performance of:
reject vs filter
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>
Tests:
reject
const foo = ['field1', 'field2', 'field3', 'field4', 'field5']; _.reject(foo, nextField => nextField === 'field4');
filter
const foo = ['field1', 'field2', 'field3', 'field4', 'field5']; foo.filter(i => i === 'field4')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
reject
filter
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
5 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36
Browser/OS:
Chrome 141 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
reject
11375871.0 Ops/sec
filter
30986798.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks on MeasureThat.net. **Benchmark Overview** The provided benchmark measures the performance difference between two approaches: rejecting an element in a JavaScript array using `lodash`'s `_reject()` function and filtering out an element from the same array using vanilla JavaScript's `filter()` method. **Options Compared** Two options are compared: 1. **_reject() (Lodash)**: This function is part of the popular Lodash library, which provides a collection of reusable functions for various tasks, including array manipulation. 2. **Filter () (Vanilla JavaScript)**: This is the native `filter()` method in JavaScript arrays. **Pros and Cons** **_reject() (Lodash)** Pros: * Efficient implementation for rejecting elements * Built-in support for handling different types of values * Part of a comprehensive library, making it easier to use other Lodash functions together Cons: * Requires an additional library download (lodash.js) * May have overhead due to the need to import and initialize the library **Filter () (Vanilla JavaScript)** Pros: * No additional libraries required * Native implementation, ensuring optimal performance * Easy to understand and implement Cons: * Can be slower for large arrays or complex filtering conditions * Requires explicit implementation of the filtering logic **Library: Lodash** Lodash is a popular JavaScript library that provides a collection of reusable functions for various tasks. `_reject()` is one of these functions, which allows you to reject elements from an array based on a provided condition. **Special JS Feature/ Syntax: None** This benchmark does not use any special JavaScript features or syntax beyond the standard `filter()` and `_reject()` methods. **Other Alternatives** If you want to explore other alternatives for rejecting elements in an array, consider using: 1. `Array.prototype.filter()`: The native `filter()` method is a good alternative to Lodash's `_reject()`. 2. `Array.prototype.every()`: Although not directly related to rejection, `every()` can be used with a negative condition to filter out unwanted elements. 3. `Some()` and `Every()` functions from the `Array.prototype` methods or libraries like Ramda. In conclusion, this benchmark provides a useful comparison between two approaches: Lodash's `_reject()` function and vanilla JavaScript's `filter()` method. The choice between these options depends on your specific requirements, performance considerations, and personal preference.
Related benchmarks:
without vs filter
Array.prototype.filter vs Lodash 4.17.5 filter
lodash.filter vs js native
Lodash.filter vs Lodash.without
Lodash filter VS native filter (with Lodash actually loaded)
Comments
Confirm delete:
Do you really want to delete benchmark?