Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
startswith vs includes vs not match includes
(version: 0)
Comparing performance of:
includes vs startsWith vs includes not match
Created:
5 years ago
by:
Guest
Jump to the latest result
Tests:
includes
const str = "https://firebase.com/this/is/a/long/thing" str.includes("firebase")
startsWith
const str = "https://firebase.com/this/is/a/long/thing" str.startsWith("https://firebase")
includes not match
const str = "https://firebase.com/this/is/a/long/thing" str.includes("firebasc")
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
includes
startsWith
includes not match
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):
I'd be happy to explain the JavaScript microbenchmark on MeasureThat.net. **Benchmark Overview** The benchmark compares three string matching methods: `startsWith`, `includes`, and `not matches` (i.e., `includes(false)` or `includes(undefined)`). The purpose of this benchmark is to measure the performance differences between these methods for a specific use case. **Options Compared** 1. **startsWith**: Returns `true` if the string starts with the specified value. 2. **includes**: Returns `true` if the string includes the specified value anywhere in its content. 3. **not matches (includes(false) or includes(undefined))**: This is not a standard JavaScript method, but rather an optimization technique used by some browsers to avoid unnecessary string comparisons. **Pros and Cons** 1. **startsWith**: * Pros: Fast and efficient for matching strings that start with a specific value. * Cons: May return false positives if the input string contains the specified value at the end (e.g., "abcdef" with `startsWith("def")`). 2. **includes**: * Pros: Flexible and accurate, as it searches for the specified value anywhere in the string. * Cons: Generally slower than `startsWith`, especially for large strings or specific values that don't occur frequently. 3. **not matches (includes(false) or includes(undefined))**: * This optimization technique can be beneficial when the input string is guaranteed to not contain the specified value, as it avoids unnecessary comparisons. **Library and Special Features** None of these methods rely on external libraries or special JavaScript features beyond standard language constructs. **Benchmark Results** The benchmark results show the execution frequency per second for each method: | Test Name | Execution Frequency (per second) | | --- | --- | | startsWith | 36030812.0 | | includes | 28904254.0 | | includes not match | 28812272.0 | As expected, `startsWith` performs the best, followed closely by `includes`. The "not matches" method is likely optimized for specific use cases and doesn't provide meaningful results in this benchmark. **Alternatives** If you're interested in exploring alternative string matching methods or optimizations, consider: 1. **RegExp**: Regular expressions can be used to perform complex string searches with high accuracy. 2. **Substring Methods**: Other substring-related methods like `indexOf()`, `lastIndexOf()`, or `split()` might offer different performance profiles depending on the specific use case. Please note that these alternatives may not be directly comparable to the original benchmark, as they often involve different performance characteristics and trade-offs.
Related benchmarks:
javascript startsWith() vs includes()
Js Search - String StartsWith vs Includes
check application json startswith vs includes
startsWith vs includes (when no match)
includes with regex vs startWith
Comments
Confirm delete:
Do you really want to delete benchmark?