Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
find vs indexOf (Array prototype methods)
(version: 0)
Measuring which is faster
Comparing performance of:
Array.prototype.find vs Array.prototype.findIndex
Created:
3 years ago
by:
Guest
Jump 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.indexOf(1E5);
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:
9 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; rv:128.0) Gecko/20100101 Firefox/128.0
Browser/OS:
Firefox 128 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array.prototype.find
3178.6 Ops/sec
Array.prototype.findIndex
15284.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what's being tested. **Overview** The benchmark is designed to measure the performance difference between two methods: `find` and `indexOf` on the Array prototype in JavaScript. The tests are run on different browsers (in this case, Firefox 105) to determine which method is faster. **What is being compared?** The test compares the execution speed of the following two methods: 1. `Array.prototype.find(item => item == 1E5)`: This method returns the first element in the array that satisfies the condition. In this case, it's checking for an element with a value equal to 100,000 (1E5). 2. `Array.prototype.indexOf(1E5)`: This method returns the index of the first occurrence of the specified element. **Pros and Cons** Here are some pros and cons of each approach: * `find`: + Pros: More concise and expressive code, allows for a more functional programming style. + Cons: May have higher overhead due to the need to create a callback function and iterate through the array. * `indexOf`: + Pros: Generally faster and more optimized than `find`, as it uses a linear search algorithm with bounds checking. + Cons: May not be suitable for large arrays or complex searches, as it can become slow. **Library usage** In this benchmark, no external libraries are used. The `Array.prototype.find` method is an ECMAScript Standardized Method (ESM), which means it's a built-in feature of the JavaScript language. **Special JS features or syntax** The benchmark uses a few special features: * `const` and `let` declarations for variable scope. * Arrow functions (`item => item == 1E5`) for concise code. * `while` loop for creating an array with a large number of elements. No other special features are used in this benchmark. **Alternatives** If you wanted to measure the performance of these methods, you could use other approaches: * Use a different method altogether, such as `filter()` or a custom implementation using a binary search algorithm. * Measure the performance of each method on different types of data (e.g., arrays vs. objects). * Compare the performance of different browsers and versions. Keep in mind that benchmarking can be complex, as it involves many factors like CPU architecture, memory management, and caching effects.
Related benchmarks:
find vs findIndex (Array prototype methods)
find vs findIndex (Array prototype methods) 22
findIndex vs indexOf for simple array 2
find vs findIndex (Array prototype methods) stop at first found
Comments
Confirm delete:
Do you really want to delete benchmark?