Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
RegEx.test vs. String.includes vs. String.match Case Insensitive
(version: 0)
Comparing performance of:
RegEx.test vs String.includes vs String.match
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var string = "HELLO world!"; var regex = /Hello/i;
Tests:
RegEx.test
regex.test(string);
String.includes
string.toUpperCase().includes("Hello".toUpperCase());
String.match
string.match("Hello");
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
RegEx.test
String.includes
String.match
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 break down the benchmark and its components. **Benchmark Overview** The benchmark compares three approaches for case-insensitive string matching: 1. `RegEx.test()` 2. `String.includes()` with `toUpperCase()` transformation 3. `String.match()` with a regular expression These approaches are compared to determine which one is faster on modern web browsers, specifically Chrome 114, running on Mac OS X 10.15.7. **Approaches Compared** 1. **RegEx.test()**: This method uses a regular expression engine to perform case-insensitive matching. 2. **String.includes()` with `toUpperCase()` transformation**: This approach converts the input string and the regex pattern to uppercase using `toUpperCase()` before performing the comparison. The `.includes()` method is then used to check if the substring exists in the original string, but since the search is done in uppercase, it's effectively a case-insensitive comparison. 3. **String.match()` with a regular expression**: This approach uses a regular expression engine to perform case-insensitive matching directly. **Pros and Cons** * **RegEx.test()**: + Pros: Can be used for more complex pattern matching, flexible syntax, and can handle Unicode characters. + Cons: May have slower performance due to the complexity of the regular expressions. * **String.includes()` with `toUpperCase()` transformation**: + Pros: Easy to use, fast performance, and doesn't require special knowledge of regular expressions. + Cons: May lose case sensitivity, and the `.includes()` method is not designed for regex pattern matching. * **String.match()` with a regular expression**: + Pros: Fast performance, can handle complex patterns, and provides the full power of regular expressions. + Cons: Requires knowledge of regular expressions, may have slower performance if the pattern is complex. **Library and Purpose** In this benchmark, no libraries are explicitly mentioned. However, the use of `String.includes()` and `String.match()` suggests that these methods are part of the JavaScript standard library or a browser-specific implementation. **Special JS Feature/Syntax** There are no special JavaScript features or syntax used in this benchmark beyond what's typically available in modern JavaScript implementations. **Other Alternatives** If you're interested in exploring other approaches, consider: * Using `String.prototype.localeCompare()` for case-insensitive string comparison. * Implementing a custom regular expression engine, such as using a library like `esreg` or creating your own implementation. * Comparing with other browser-specific implementations, like `Browser.match()`, if available. Keep in mind that the specific approach chosen often depends on the use case and personal preference. The benchmark result can provide valuable insights into performance differences between these approaches.
Related benchmarks:
RegEx.test vs. String.includes case insensitive
RegEx.test vs. String.includes vs. String.match insensitive
Case insensitive RegEx.test vs. String.includes when string doesn’t match
Case Insensitive RegEx.test vs. String.includes
regex vs includes - case insensitive
Comments
Confirm delete:
Do you really want to delete benchmark?