Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
startswith vs includes (exact string)
(version: 0)
Comparing performance of:
includes vs startsWith
Created:
2 years ago
by:
Guest
Jump to the latest result
Tests:
includes
const str = "https://firebase.com/this/is/a/long/thing" str.includes("https://firebase")
startsWith
const str = "https://firebase.com/this/is/a/long/thing" str.startsWith("https://firebase")
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
includes
startsWith
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 details of the MeasureThat.net benchmark. **What is being tested?** The benchmark measures the performance difference between two string manipulation methods: `includes` and `startsWith`. Specifically, it tests how fast these methods can check if a given string starts with or includes another specific substring (`"https://firebase/"`). **Options compared** There are two options being compared: 1. **String.prototype.includes()**: This method checks if the string contains the specified value anywhere in its sequence. 2. **String.prototype.startsWith()**: This method checks if the string starts with the specified value. **Pros and Cons of each approach:** 1. **String.prototype.includes()** * Pros: + More flexible, as it can check for any substring within the string, not just a prefix. + Can be more efficient in some cases, as it only needs to scan the string until it finds the first match. * Cons: + Typically slower than `startsWith` because of the scanning process. 2. **String.prototype.startsWith()** * Pros: + Faster, especially for short strings or prefixes that appear early on in the original string. + Can be more efficient when working with long strings, as it only needs to check the initial characters. * Cons: + Less flexible than `includes`, as it only checks for a specific prefix. **Other considerations:** 1. **Regular expressions**: Some browsers and engines use regular expressions under the hood for both `includes` and `startsWith`. This can affect performance, as regex processing can be more computationally intensive. 2. **Optimizations**: Modern JavaScript engines often have optimizations in place to improve performance for common string operations like these. **Special JS feature:** There is no special JavaScript feature or syntax being used here; the focus is on a fundamental operation that's widely applicable. **Benchmark result analysis:** The latest benchmark results show a significant difference in execution speed between `includes` and `startsWith`. The `includes` test takes about 64,433,226 executions per second (UAString), while the `startsWith` test averages around 14,585,809 executions per second. This indicates that, on average, `startsWith` is faster than `includes`, especially considering the optimization potential in modern browsers. **Alternatives:** Some alternatives for string manipulation or comparison could include: 1. **Substring() method**: A more traditional approach to extracting a specific part of a string. 2. **RegExp.test()**: Using regular expressions to match patterns within strings (although, as mentioned earlier, this might be under the hood for both `includes` and `startsWith`). 3. **Regular expression-based solutions**: Implementing custom regex-based solutions using String.prototype.replace or similar methods. Keep in mind that MeasureThat.net is focused on measuring JavaScript performance, specifically with respect to string manipulation operations like these.
Related benchmarks:
javascript startsWith() vs includes()
Js Search - String StartsWith vs Includes
check application json startswith vs includes
startsWith vs includes when no match
startsWith vs includes (when no match)
Comments
Confirm delete:
Do you really want to delete benchmark?