Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Js Search -String IndexOf vs Includes
(version: 0)
Comparing performance of:
Index Of vs Includes
Created:
4 years ago
by:
Guest
Jump to the latest result
Tests:
Index Of
var a = 'hello#a#bc#helloa'; var b = a.indexOf('helloa');
Includes
var a = 'hello#a#bc#helloa'; var b = a.includes('helloa');
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Index Of
Includes
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/131.0.0.0 Safari/537.36 Edg/131.0.0.0
Browser/OS:
Chrome 131 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Index Of
162923632.0 Ops/sec
Includes
155269088.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 Purpose** The main goal of this benchmark is to compare the performance of two string searching methods in JavaScript: `indexOf` and `includes`. These methods are used to find the index of a specific substring within a larger string. **Options Compared** Two options are compared: 1. **String.indexOf()**: This method searches for the first occurrence of a specified value in a string. It returns the index of the found value, or -1 if no match is found. 2. **String.includes()**: This method checks if a string includes a specified value (or substring) as one of its characters. It returns `true` if the value is found, and `false` otherwise. **Pros and Cons** * `indexOf()`: * Pros: + Faster for searching specific substrings. + More flexible, allowing for searching from any position in the string. * Cons: + May return -1 if no match is found, which can be considered as an error. + Less intuitive for some developers due to its more complex behavior. * `includes()`: + Pros: + Simpler and more intuitive than `indexOf()`. + More suitable for cases where you're checking if a string includes any of several values. **Other Considerations** The choice between these two methods depends on the specific use case. If you need to find a specific substring within a large string, `indexOf()` might be faster. However, if you're searching for multiple values and want a simple, intuitive way to do so, `includes()` is likely a better choice. **Library Used** None are explicitly mentioned in this benchmark. **Special JS Feature or Syntax** No special JavaScript features or syntaxes are used in these test cases. **Alternative Approaches** Other approaches to implement string searching include: * Using regular expressions (regex) with the `RegExp` object. * Implementing a custom search algorithm using bit manipulation or other techniques. * Utilizing third-party libraries like Lodash or String.prototype.search()
Related benchmarks:
Js Search - String StartsWith vs Includes
IndexOf vs Includes on string
find vs includes vs indexof
.includes() vs indexOf() for single-character search in string
Comments
Confirm delete:
Do you really want to delete benchmark?