Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
startsWith vs includes (same search)
(version: 0)
Comparing performance of:
includes vs startsWith
Created:
4 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:
Run details:
(Test run date:
16 days ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36
Browser/OS:
Chrome 145 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
includes
265022512.0 Ops/sec
startsWith
63552328.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks on MeasureThat.net. **Benchmark Definition and Preparation** The benchmark definition is essentially a description of what needs to be tested. In this case, there are two test cases: 1. `includes`: The script searches for the presence of a substring within a string using the `includes()` method. 2. `startsWith`: The script searches for the presence of a prefix within a string using the `startsWith()` method. The script preparation code and HTML preparation code fields are left blank, which means that MeasureThat.net will automatically generate these codes for the benchmark. **Options Compared** In this benchmark, two options are compared: 1. `includes()`: Uses the `includes()` method to search for a substring within a string. 2. `startsWith()`: Uses the `startsWith()` method to search for a prefix within a string. **Pros and Cons of Each Approach** Here's a brief analysis of each approach: * `includes()`: + Pros: Generally faster and more widely supported than `startsWith()`. + Cons: Can be slower for longer substrings or prefixes, as it uses a simple substring search algorithm. * `startsWith()`: + Pros: Often faster for longer prefixes or substrings, as it uses a more efficient algorithm that takes advantage of the prefix. + Cons: Less widely supported than `includes()` and may not work in older browsers. **Library** In both test cases, no libraries are explicitly mentioned. However, the `includes()` method is built-in to JavaScript, while the `startsWith()` method was introduced in ECMAScript 2017 (ES7). **Special JS Feature/Syntax** Neither of the two methods relies on any special JavaScript features or syntax that would require additional explanation. **Other Alternatives** There are other alternatives for string searching in JavaScript, such as using regular expressions. For example: * `String.prototype.indexOf()`: Searches for a substring within a string and returns its index. * `String.prototype.lastIndexOf()`: Searches for the last occurrence of a substring within a string and returns its index. However, these alternatives may not be included in this benchmark, as they are not directly compared to the `includes()` and `startsWith()` methods. Overall, MeasureThat.net's benchmark provides a simple and concise way to compare the performance of two common JavaScript methods for searching substrings or prefixes within strings.
Related benchmarks:
javascript startsWith() vs includes()
Js Search -String IndexOf vs Includes
Js Search - String StartsWith vs Includes
check application json startswith vs includes
Comments
Confirm delete:
Do you really want to delete benchmark?