Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
startswith vs includes
(version: 0)
Comparing performance of:
includes vs startsWith
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")
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:
yesterday
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36
Browser/OS:
Chrome 147 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
includes
216290752.0 Ops/sec
startsWith
52234820.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Measuring JavaScript performance can be quite complex, especially when considering the various libraries and features used in modern web development. **Benchmark Overview** The provided benchmark measures the performance difference between two string methods: `includes` and `startsWith`. Both methods are part of the ECMAScript standard, but they behave differently. **Options Compared** In this benchmark, two options are compared: 1. **`str.includes("firebase")`**: This method checks if a given string ("firebase") is present at the beginning of another string (`str`). It returns `true` if the substring is found, and `false` otherwise. 2. **`str.startsWith("https://firebase")`**: This method checks if a given string ("https://firebase") is equal to the beginning of another string (`str`). It returns `true` if the substring matches, and `false` otherwise. **Pros and Cons** 1. **`includes` method:** * Pros: + More flexible, as it can search for any part of the string within a larger context. + Can be faster for larger strings, since it only needs to iterate through a portion of the string. * Cons: + Less efficient when searching for an exact match at the beginning of the string. 2. **`startsWith` method:** * Pros: + More efficient when searching for an exact match at the beginning of the string. + Can be faster for smaller strings, since it only needs to compare a short substring. * Cons: + Less flexible than `includes`, as it can only search for an exact match. **Library Usage** There is no explicit library usage in this benchmark. However, both methods rely on the JavaScript engine's implementation of string matching algorithms. **Special JS Features or Syntax** This benchmark does not involve any special JavaScript features or syntax beyond the standard `includes` and `startsWith` methods. **Other Alternatives** If you're looking for alternatives to these string methods, consider: 1. **Using a regular expression**: You can use the `RegExp` object to search for patterns in strings using regular expressions. This approach is more flexible than both `includes` and `startsWith`, but it may be slower due to the overhead of compiling and executing the regex pattern. 2. **Manual string searching**: If you need extreme performance, you could implement a simple manual string searching algorithm using bitwise operations or other low-level techniques. In general, for most web development use cases, the standard `includes` and `startsWith` methods are sufficient and efficient enough. However, if you have specific requirements that necessitate more flexibility or performance, consider exploring regular expressions or alternative algorithms.
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?