Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
RegEx.test vs. String.includes case insensitive
(version: 0)
Comparing performance of:
RegEx.test vs String.includes
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var string = "Hello world!"; var regex = new RegExp('hello', 'i');;
Tests:
RegEx.test
regex.test(string);
String.includes
string.toUpperCase().includes("hello".toUpperCase());
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:
15 days ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36
Browser/OS:
Chrome 147 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
RegEx.test
68021992.0 Ops/sec
String.includes
30450104.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down what is being tested in this benchmark. **What is being compared:** The benchmark compares the performance of two approaches: 1. **`String.includes` with case insensitive**: This approach uses the `includes()` method to search for the substring `"hello"` within the string `"Hello world!"`. The `i` flag at the end of the regular expression tells JavaScript to perform a case-insensitive match. 2. **`RegExp.test`**: This approach uses the `test()` method with a regular expression to search for the substring `"hello"` within the string `"Hello world!"`. The regular expression is created using the `new RegExp('hello', 'i')` constructor, which also performs a case-insensitive match. **Pros and cons of each approach:** 1. **`String.includes`**: This approach has the advantage of being more straightforward and easier to read. It's also less error-prone since it doesn't require manual management of the regular expression flags. * Disadvantage: Performance-wise, `includes()` might be slower than a custom implementation using `RegExp.test`. 2. **`RegExp.test`**: This approach provides better performance since it can take advantage of the optimized C++ engine used by V8 (the JavaScript engine in Chrome). * Advantages: More control over the regular expression flags and pattern. * Disadvantage: More complex to read and maintain, especially for those without experience with regular expressions. **Library used:** There is no specific library mentioned in the benchmark definition. However, `RegExp` is a built-in JavaScript class that provides support for working with regular expressions. **Special JS feature or syntax:** There are no special features or syntaxes being tested in this benchmark. **Other alternatives:** If you wanted to compare other approaches, here are some alternatives: * **Using `String.indexOf()`**: Similar to `includes()`, but returns the index of the first match instead of a boolean value. * **Using a native string method like `startsWith()` or `endsWith()`**: These methods can be used in combination with `toLowerCase()` or `toUpperCase()` to achieve case-insensitive matching. * **Using a regular expression with a different flag**: For example, using the `'gi'` flag for global and insensitive matching. Keep in mind that these alternatives may have different performance characteristics compared to the approaches being tested.
Related benchmarks:
Case insensitive RegEx.test vs. String.includes when string doesn’t match
RegEx.test vs. String.includes incasesensitive
Case Insensitive RegEx.test vs. String.includes
regex vs includes - case insensitive
Comments
Confirm delete:
Do you really want to delete benchmark?