Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
JS Find vs FindIndex vs Filter
(version: 0)
Comparing performance of:
FindIndex vs Find vs Filter
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var data = new Array(20000); data.fill({}); data.map((d,i) => ({redID:i, blueID:i}));
Tests:
FindIndex
var index = data.findIndex(f => f.redID === 19987 && f.blueID === 19987);
Find
var test = data.find(f => f.redID === 19987 && f.blueID === 19987);
Filter
var test = data.filter(f => f.redID === 19987 && f.blueID === 19987);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
FindIndex
Find
Filter
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; rv:133.0) Gecko/20100101 Firefox/133.0
Browser/OS:
Firefox 133 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
FindIndex
13768.0 Ops/sec
Find
13386.1 Ops/sec
Filter
13217.7 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview of the Benchmark** The benchmark being tested on MeasureThat.net is the performance comparison of three JavaScript methods: `findIndex`, `find`, and `filter`. These methods are used to search for an object in an array that meets specific conditions. **What is Tested?** The provided JSON defines a single benchmark with three individual test cases: 1. `FindIndex`: Tests the `findIndex` method, which returns the index of the first element in the array that satisfies the provided condition. 2. `Find`: Tests the `find` method, which returns the value of the first element in the array that satisfies the provided condition. 3. `Filter`: Tests the `filter` method, which creates a new array with all elements that satisfy the provided condition. **Options Compared** The three methods are compared for their performance, and we can analyze them as follows: * **FindIndex**: This method returns the index of the first element in the array that satisfies the condition. It is generally faster than `find` or `filter` because it stops searching once it finds a match. * **Find**: This method returns the value of the first element in the array that satisfies the condition. It has to search the entire array, which makes it slower than `findIndex`. * **Filter**: This method creates a new array with all elements that satisfy the condition. While it can be faster for large arrays because it doesn't have to search the entire array, it also creates a new array and can be slower than a simple loop. **Pros and Cons of Each Approach** Here are some pros and cons of each approach: * **FindIndex**: Pros: It's fast because it stops searching once it finds a match. Cons: If no element matches the condition, it returns -1, which might not be desirable in all cases. * **Find**: Pros: It returns the actual value of the first matching element. Cons: It has to search the entire array, making it slower than `findIndex`. * **Filter**: Pros: Creates a new array with matching elements, making it suitable for transforming arrays. Cons: It creates a new array and can be slower than a simple loop. **Library Usage** There is no library explicitly mentioned in the provided JSON, but JavaScript's built-in methods (`findIndex`, `find`, and `filter`) are used throughout the benchmark. **Special JS Feature or Syntax (Not Applicable)** Since the benchmark only uses built-in JavaScript methods and doesn't involve any special features like async/await, promises, or decorators, there is no additional syntax to explain.
Related benchmarks:
FindIndex + splice vs filter FindIndex
JS Array IndexOf vs includes vs findIndex vs find 5
findIndex vs indexOf vs find vs filter - JavaScript performance
findIndex vs indexOf - JavaScript performance v2
Comments
Confirm delete:
Do you really want to delete benchmark?