Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
findIndex vs indexOf vs contains
(version: 1)
Comparing performance of:
startWith vs indexOf vs includes
Created:
4 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var arr = '+12321313eefs,dmfsmfksf'
Tests:
startWith
var index = arr.startsWith('+');
indexOf
var index = arr.indexOf('+');
includes
var index = arr.includes('+');
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
startWith
indexOf
includes
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:131.0) Gecko/20100101 Firefox/131.0
Browser/OS:
Firefox 131 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
startWith
1016395200.0 Ops/sec
indexOf
1030295360.0 Ops/sec
includes
977669120.0 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. **Benchmark Overview** The benchmark is designed to compare the performance of three different methods for searching for a specific value within an array: 1. `startsWith`: Checks if the array starts with the specified value. 2. `indexOf`: Returns the index of the first occurrence of the specified value in the array. 3. `includes`: Returns a boolean indicating whether the array includes the specified value. **Options Compared** The benchmark is comparing the performance of these three methods on a sample array containing only one element: `'+12321313eefs,dmfsmfksf'`. The array contains non-ASCII characters, which may affect the performance of certain browsers. **Pros and Cons of Each Approach** 1. `startsWith`: * Pros: Simple and efficient for searching from the beginning of an array. * Cons: May be slower than other methods if the value is not found at the start of the array. 2. `indexOf`: * Pros: Returns the index of the first occurrence, which can be useful for finding a specific element in an array. * Cons: May perform a linear search through the entire array, making it slower than `startsWith`. 3. `includes`: * Pros: Simple and efficient for searching within the middle or end of an array. * Cons: May be slower than `startsWith` if the value is not found in the array. **Library Usage** The benchmark does not appear to use any external libraries. The script preparation code defines a sample array, and the HTML preparation code (which is empty) likely sets up the environment for running JavaScript benchmarks. **Special JS Features or Syntax** This benchmark does not appear to utilize any special JavaScript features or syntax beyond the standard `startsWith`, `indexOf`, and `includes` methods. **Other Alternatives** If you were to rewrite this benchmark, you could consider alternative search methods, such as: 1. `Array.prototype.some()` or `Array.prototype.every()`: These methods can be used for more complex searches, but may introduce additional overhead. 2. `String.prototype.indexOf()` on a substring of the array element: This approach could be faster than searching the entire array, but may not work for all cases (e.g., when searching for a value within a nested array). 3. Native methods like `Uint8Array.prototype.indexOfU16()`: Some browsers support native methods for searching within specific types of arrays, which can be faster than using standard JavaScript methods. Keep in mind that the performance differences between these alternatives may vary depending on the browser and system configuration being tested.
Related benchmarks:
index vs lastindexof empty with startIndex set to 0
indexOf vs findIndex with a simple case
findIndex vs indexOf for simple array 2
indexOf vs findIndex simple X
Comments
Confirm delete:
Do you really want to delete benchmark?