Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
IndexOf vs Includes in string
(version: 0)
Banana
Comparing performance of:
IndexOf vs Includes
Created:
6 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var string = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.'
Tests:
IndexOf
string.indexOf('tempor')
Includes
string.includes('tempor')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
IndexOf
Includes
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36
Browser/OS:
Chrome 145 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
IndexOf
96375992.0 Ops/sec
Includes
93135560.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON benchmark definition and explain what's being tested. **Benchmark Definition** The benchmark is defined by two test cases: 1. `string.indexOf('tempor')` (Test Name: "IndexOf") 2. `string.includes('tempor')` (Test Name: "Includes") These two functions are being compared, which suggests a performance comparison between the two methods of searching for a specific substring within a string. **Options Compared** The options being compared are: * `indexOf()`: The traditional method of finding the index of a substring within a string. * `includes()`: A newer method introduced in ECMAScript 2019 (ES11), which provides a more concise and readable way to check if a string includes a certain value. **Pros and Cons** * **`indexOf()`**: + Pros: Widely supported across older browsers, easy to implement. + Cons: Can be slower and less efficient than `includes()`, as it has to iterate through the entire string to find the match. * **`includes()`**: + Pros: Faster and more efficient than `indexOf()`, as it can stop searching as soon as it finds a match. + Cons: Requires ECMAScript 2019 (ES11) support, may not be compatible with older browsers. **Other Considerations** The benchmark is set up to measure the performance of these two methods in different scenarios. The test string is designed to contain a relatively common word (`"tempor"`), which should help to isolate the differences between the two methods. **Library and Purpose** No specific libraries are mentioned in the JSON definition. However, it's worth noting that some JavaScript engines may use internal optimizations or caching mechanisms that could impact the performance of these tests. **Special JS Feature or Syntax** There is no special JavaScript feature or syntax being tested here. The focus is solely on comparing the performance of two simple string methods. **Other Alternatives** If you're interested in testing other string methods, you might consider adding additional test cases, such as: * Using `includes()` with a regex pattern * Comparing `startsWith()`, `endsWith()`, and `indexOf()` methods * Testing different string encodings or character sets However, these alternatives are not part of the provided JSON benchmark definition. Overall, this benchmark is designed to help developers understand the performance differences between traditional `indexOf()` and newer `includes()` methods in JavaScript.
Related benchmarks:
IndexOf vs Includes in Larger string
IndexOf vs Includes in string 333
IndexOf vs Includes in string with check
IndexOf vs Includes in string as boolean
IndexOf vs Includes in string 2
Comments
Confirm delete:
Do you really want to delete benchmark?