Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
RegEx.test vs. String.includes checking if https:// or http:// exists
(version: 0)
Comparing performance of:
RegEx.test vs String.includes
Created:
2 years ago
by:
Guest
Go to the latest result
Script Preparation code:
var string = "https://www.measurethat.com"; var regex = /^https?:\/\//;
Tests:
RegEx.test
regex.test(string);
String.includes
string.includes("https://") || string.includes("http://")
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
RegEx.test
String.includes
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0
Browser/OS:
Chrome 121 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
String.includes
12.6M/s
RegEx.test
6.9M/s
View exact numbers
Test name
Executions per second
✓
String.includes
12,580,739 Ops/sec
RegEx.test
6,926,050 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to explain what's tested in the provided benchmark. **Overview** The benchmark measures the performance difference between using regular expressions (`regex`) and string includes (`includes`) methods to check if a URL (HTTPS or HTTP) exists in a given string. The goal is to determine which approach is faster for this specific use case. **Options Compared** Two options are compared: 1. **Regular Expressions (RegEx)**: Using the `^https?:\/\/\\//` regular expression pattern to match the URL. 2. **String Includes**: Checking if the URL exists as a substring in the original string using `string.includes("https://") || string.includes("http://")`. **Pros and Cons** * **Regular Expressions (RegEx)**: + Pros: Can be more efficient for specific pattern matching, provides more flexibility. + Cons: Requires specialized syntax, can be slower due to the overhead of compiling and executing regular expressions. * **String Includes**: + Pros: Simple and straightforward, no additional syntax required. + Cons: May be slower than RegEx due to the overhead of searching for substrings. **Other Considerations** The benchmark also provides some useful information: * The **Script Preparation Code** sets up a test string (`string`) and a regular expression pattern (`regex`). * The **Html Preparation Code** is empty, indicating that no HTML-related code needs to be executed. * The **Browser**, **DevicePlatform**, and **OperatingSystem** fields provide information about the browser and device used for each benchmark result. **Library Used** The `includes()` method uses the String.prototype.includes() method, which is a built-in JavaScript method. It's not a separate library, but rather a part of the standard library. **Special JS Feature/Syntax** There are no special JavaScript features or syntaxes used in this benchmark. The regular expression pattern (`^https?:\/\/\\//`) uses a common regex syntax, and the string includes code is straightforward JavaScript syntax. **Alternatives** Other alternatives for comparing the performance of RegEx and string includes methods might include: * Using other regular expression patterns or syntaxes. * Comparing the performance with other string manipulation methods (e.g., using indexOf() or substring()). * Testing different browser versions or operating systems to see how they affect performance. Keep in mind that this benchmark is focused on a specific use case, and alternative benchmarks might be necessary for more general use cases.
Related benchmarks
Test regex2
.startsWith() vs .test() vs .match() vs .indexOf()
RegEx.test (with inline regex) vs. String.includes vs. String.match
Long regex test vs string includes
Comments
Confirm delete:
Do you really want to delete benchmark?