Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
#2 Array Includes vs. Find
(version: 0)
Comparing performance of:
Array.includes vs Array.find
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
var list = ['aaa', 'bbb', 'ccc'];
Tests:
Array.includes
var exists = list.includes('abc');
Array.find
var item = list.find(v => v === 'abc');
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Array.includes
Array.find
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Browser/OS:
Chrome 126 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array.includes
16654104.0 Ops/sec
Array.find
17671246.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested. **Benchmark Overview** The benchmark, titled "#2 Array Includes vs. Find", tests the performance difference between two JavaScript array methods: `includes()` and `find()`. The benchmark is designed to measure which method is more efficient when searching for a specific element within an array. **Options Compared** Two options are being compared: 1. **`Array.includes()`**: This method returns `true` if an array contains the specified value, or `false` otherwise. 2. **`Array.find()`**: This method returns the first element in the array that satisfies the provided testing function, or `undefined` if no elements satisfy it. **Pros and Cons of Each Approach** * **`Array.includes()`**: + Pros: Simple, easy to understand, and widely supported by browsers. + Cons: Can be slower than `find()` for large arrays because it may require a linear search through the array. * **`Array.find()`**: + Pros: More expressive and flexible than `includes()`, allowing for more complex search conditions. + Cons: May be slower than `includes()` for small arrays due to the overhead of creating and executing a callback function. **Library/Functionality Used** In this benchmark, no libraries or external functions are used beyond the built-in JavaScript array methods. However, it's worth noting that some modern browsers may have additional features or optimizations enabled for these methods, which could affect performance. **Special JS Feature/Syntax** There is no special JavaScript feature or syntax being tested in this benchmark. The focus is solely on comparing the performance of `includes()` and `find()`. **Other Alternatives** If you're looking to optimize array searches, here are some alternative approaches: 1. **Manual indexing**: Using a manual index to access specific elements within an array. 2. **Binary search**: Implementing a binary search algorithm to find specific elements in large arrays. 3. **Sparse arrays**: Using sparse arrays (arrays with holes) to improve performance when working with large datasets. Keep in mind that these alternatives may require more code and are generally less straightforward than using built-in array methods like `includes()` and `find()`.
Related benchmarks:
find vs includes
IndexOf vs Includes vs find
array indexOf vs includes vs some v3
find vs includes vs indexof
Comments
Confirm delete:
Do you really want to delete benchmark?