Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
find vs includes
(version: 0)
Comparing performance of:
find vs includes
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var array = ['banana', 'sausage', 'jesus']
Tests:
find
array.find(f => f == 'banana' );
includes
array.includes('banana');
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
find
includes
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
9 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36
Browser/OS:
Chrome 138 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
find
25438440.0 Ops/sec
includes
23946134.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to explain the benchmark and its components. **Benchmark Overview** The provided benchmark compares the performance of two JavaScript methods: `array.find()` and `array.includes()`. The test creates an array with three strings, including "banana", and then checks if each string is equal to "banana" using both methods. **Options Compared** Two options are compared: 1. `array.find(f => f == 'banana')`: This method returns the first element in the array that satisfies the provided condition (in this case, equality with "banana"). If no such element exists, it returns `undefined`. 2. `array.includes('banana')`: This method checks if the array contains the specified value ("banana") and returns a boolean result indicating whether it does or not. **Pros and Cons** Here's a brief summary of the pros and cons of each approach: 1. `array.find()`: * Pros: Can be more efficient for large arrays, as it stops iterating as soon as it finds the match. * Cons: Returns `undefined` if no match is found, which might not be desirable in some cases. Also, it's a method call, so there's an overhead associated with invoking a function. 2. `array.includes()`: * Pros: Always returns a boolean result (true or false), making it easier to handle the outcome. * Cons: Requires iterating over the entire array, which can be slower for large arrays. **Library Usage** There is no explicit library usage in this benchmark. However, some browsers might use internal libraries or optimizations that affect the performance of these methods. For example, Chrome's `includes()` method uses a binary search algorithm internally to improve performance. **Special JS Features/Syntax** There are no special JavaScript features or syntax used in this benchmark. The code is simple and straightforward. **Other Alternatives** If you need to compare other array methods, consider the following alternatives: * `array.indexOf()`: Similar to `includes()`, but returns the index of the first occurrence instead of a boolean result. * `array.slice().indexOf()` or `array.filter()`: These approaches can be used to implement custom array search methods, but might incur additional overhead due to method call and iteration. In summary, this benchmark compares two common JavaScript array methods: `find()` and `includes()`. While `find()` has some advantages in terms of efficiency for large arrays, it returns `undefined` if no match is found. On the other hand, `includes()` always returns a boolean result but requires iterating over the entire array.
Related benchmarks:
includes vs find vs some
IndexOf vs Includes vs find
find vs includes vs indexof
#2 Array Includes vs. Find
Comments
Confirm delete:
Do you really want to delete benchmark?