Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
find vs findIndex with accesing the elemnt through index
(version: 0)
Measuring which is faster test
Comparing performance of:
Array.prototype.find vs Array.prototype.findIndex
Created:
2 years ago
by:
Guest
Go to the latest result
Script Preparation code:
var arr = []; var i = 0; while (i <= 1E5) arr[i] = i++;
Tests:
Array.prototype.find
const item = arr.find(item => item == 1E5);
Array.prototype.findIndex
const index = arr.findIndex(item => item == 1E5); const element = arr[index];
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Array.prototype.find
Array.prototype.findIndex
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
Browser/OS:
Chrome 127 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Array.prototype.findIndex
7K/s
Array.prototype.find
7K/s
View exact numbers
Test name
Executions per second
✓
Array.prototype.findIndex
6,948 Ops/sec
Array.prototype.find
6,752 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON data and explain what's being tested on MeasureThat.net. **Benchmark Definition** The benchmark measures which method is faster: using `find` or `findIndex` to access an element in an array by its index. The test case generates a large array of 100,000 elements, where each element is set to its index value (e.g., `arr[0] = 0`, `arr[1] = 1`, and so on). **Options Compared** The two options being compared are: 1. **`Array.prototype.find`**: This method returns the first element in an array that satisfies a provided condition, or undefined if no such element is found. 2. **`Array.prototype.findIndex`**: This method returns the index of the first element in an array that satisfies a provided condition, or -1 if no such element is found. **Pros and Cons** Here are some pros and cons of each approach: * **`find`**: + Pros: Simple to implement, easy to read. + Cons: May be slower than `findIndex` for large arrays because it needs to iterate through the entire array until it finds a match, even if it's not necessary (e.g., if the condition is false for most elements). * **`findIndex`**: + Pros: Faster than `find` for large arrays because it stops iterating as soon as it finds a match. + Cons: More complex to implement, may be harder to understand. **Library and Purpose** There are no external libraries used in this benchmark. The array is created using JavaScript's built-in syntax. **Special JS Feature or Syntax** None of the test cases uses any special JavaScript features or syntax that would affect their performance. They only use standard JavaScript methods (`find`, `findIndex`) and basic array operations (iteration). **Other Alternatives** If you were to optimize this benchmark, you might consider using: 1. **`map`**: Instead of iterating through the entire array, you could use `map()` to create a new array with the index values. This would eliminate the need for indexing into the original array. 2. **NativeArray methods**: Depending on the JavaScript engine and platform, native array methods like `Array.prototype.get()` or `TypedArray.prototype[index]` might be faster than `findIndex`. 3. **SIMD instructions**: If you're targeting a modern browser that supports SIMD (Single Instruction, Multiple Data) instructions, you could use optimized SIMD implementations of the `find` and `findIndex` methods to take advantage of parallel processing. Keep in mind that these optimizations would require additional effort and expertise, and might not always lead to significant performance improvements.
Related benchmarks
find vs findIndex (Array prototype methods)
find vs findIndex (Array prototype methods) 22
find vs findIndex (Array prototype methods) - using objects
Comments
Confirm delete:
Do you really want to delete benchmark?