Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
string indexOf and includes
(version: 0)
Comparing performance of:
includes vs indexOf
Created:
5 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var str = "Test abc test test abc test test test abc test test abc";
Tests:
includes
str.includes("abc")
indexOf
str.indexOf("abc")
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
includes
indexOf
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of MeasureThat.net and explore what's being tested in this benchmark. **Overview** MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks, testing the performance of various JavaScript features and libraries under different browsers and devices. In this case, we have two simple benchmarks: 1. `indexOf` (with `includes`) 2. `str.includes("abc")` 3. `str.indexOf("abc")` **What's being tested?** The benchmarks test the performance of the `includes()` and `indexOf()` methods in JavaScript, which are part of the ECMAScript standard. **Options compared** In this case, there is only one option being compared: 1. `str.includes("abc")` 2. `str.indexOf("abc")` **Pros and Cons of each approach** * **`str.includes("abc")`**: This approach uses a substring search method to find the first occurrence of `"abc"` in the string. + Pros: Simple, straightforward implementation. + Cons: May not be as efficient as other methods for large strings or edge cases. * **`str.indexOf("abc")`**: This approach uses an indexed search method to find the index of the first occurrence of `"abc"` in the string. + Pros: Can be more efficient than `includes()` for large strings, especially when dealing with edges like the last character. Also allows for more fine-grained control over the search process. + Cons: May not be as simple or intuitive to implement as `includes()`. **Library and its purpose** In both benchmarks, no specific library is used. The JavaScript built-in functions `includes()` and `indexOf()` are used directly. **Special JS feature or syntax** None of these tests use any special JavaScript features or syntax beyond what's part of the ECMAScript standard. **Other alternatives** If you wanted to test alternative approaches for finding the first occurrence of a substring in a string, some examples might include: * Regular expressions (e.g., `str.match(/abc/)[0]`) * Looping through the string and checking each character (e.g., `for (var i = 0; i < str.length; i++) { if (str[i] === 'a' && str[i + 1] === 'b' && str[i + 2] === 'c') { return i; } }`) * Using a library like `lodash` which has an implementation of `indexOf()`
Related benchmarks:
index vs lastindexof startsWith
index vs lastindexof (last index)
indexOf vs search
.includes() vs indexOf() for single-character search in string
Comments
Confirm delete:
Do you really want to delete benchmark?