Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
startswith vs includes simple
(version: 0)
Comparing performance of:
includes vs startsWith
Created:
3 years ago
by:
Guest
Jump to the latest result
Tests:
includes
const str = "https://firebase.com/this/is/a/long/thing" str.includes("https://")
startsWith
const str = "https://firebase.com/this/is/a/long/thing" str.startsWith("https://")
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:
Run details:
(Test run date:
4 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.2 Safari/605.1.15
Browser/OS:
Safari 26 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
includes
72857576.0 Ops/sec
startsWith
115244056.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested. **What is being tested?** The test case compares two string comparison methods in JavaScript: `includes` and `startsWith`. Specifically, it measures how fast these two methods perform when checking if a string starts with a given prefix. **Options compared:** 1. **`str.includes("https://")`**: This method checks if the string `str` contains the substring `"https://"`. 2. **`str.startsWith("https://")`**: This method checks if the string `str` starts with the substring `"https://"`. **Pros and Cons of each approach:** 1. `includes()`: * Pros: More flexible, as it can check for any substring, not just a prefix. * Cons: May be slower for exact matches, especially if the search string is shorter than the original string. 2. `startsWith()`: * Pros: Faster for exact matches, as it only checks the first few characters of the string. * Cons: Less flexible, as it can only check for a specific prefix. **Other considerations:** * The test case uses no special JavaScript features or syntax beyond standard strings and comparison operators. * No libraries are mentioned in the benchmark definition or test cases. **Alternative approaches:** 1. **Using regular expressions**: Instead of using `includes()` or `startsWith()`, you could use regular expressions to achieve similar results. However, this might add unnecessary overhead due to the complexity of regular expression matching. 2. **Using a custom implementation**: Depending on your specific use case, you might want to implement your own string comparison algorithm, which could be more efficient than using built-in methods. In summary, the benchmark tests two common JavaScript string comparison methods: `includes()` and `startsWith()`. The `includes()` method is more flexible but may be slower for exact matches, while `startsWith()` is faster but less flexible.
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?