Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
RegEx.test vs. String.toLowerCase().includes vs. String.match
(version: 0)
Comparing performance of:
RegEx.test vs String.includes vs String.match
Created:
3 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var string = "Hello world!"; var regex = /Hello/;
Tests:
RegEx.test
regex.test(string);
String.includes
string.toLowerCase().includes("Hello".toLowerCase());
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:
Run details:
(Test run date:
10 months ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:139.0) Gecko/20100101 Firefox/139.0
Browser/OS:
Firefox 139 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
RegEx.test
63566184.0 Ops/sec
String.includes
2860915200.0 Ops/sec
String.match
32207720.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what's being tested. **Overview** The benchmark is comparing three different approaches to test whether a string contains a specific substring: 1. `RegEx.test()` 2. `String.toLowerCase().includes()` 3. `String.match()` **What's being tested?** * The performance of each approach in terms of the number of executions per second. **Options compared:** * **`RegEx.test()`**: This method uses a regular expression to test whether the entire string matches a given pattern. In this case, it's testing for the presence of "Hello" at the beginning of the string. * **`String.toLowerCase().includes()```**: This method converts the input string to lowercase and then checks if the specified substring exists in the original string (in lowercase). * **`String.match()```**: This method searches for a pattern in a string and returns an array with matches. In this case, it's searching for "Hello" as a whole word. **Pros and cons of each approach:** * **`RegEx.test()`**: + Pros: Can be more efficient than `String.includes()` if the regex is optimized. + Cons: May have slower performance due to the overhead of compiling and executing a regular expression. Additionally, it may not work as expected for substrings or patterns with special characters. * **`String.toLowerCase().includes()```**: + Pros: Faster performance than `RegEx.test()` since it uses a built-in method. Also, it can handle case-insensitive matching more effectively. + Cons: May have slower performance compared to native regex methods due to string conversion and method calls. Additionally, it may not work as expected for substrings or patterns with special characters. * **`String.match()```**: + Pros: Can be more efficient than `RegEx.test()` if the pattern is simple and can match whole words. It also allows for capturing groups and returning multiple matches. + Cons: May have slower performance due to the overhead of executing a search algorithm. Additionally, it may not work as expected for substrings or patterns with special characters. **Library usage** None in this benchmark. **Special JS feature/syntax** There are no specific JavaScript features or syntax being tested in this benchmark. The focus is on comparing the performance of different string manipulation methods. **Alternatives** Other alternatives to measure string matching performance could include: * Using a native regex engine, such as `RegExp.test()` * Implementing a simple substring search algorithm using loops and conditionals * Using a third-party library like Sprintf or Stringify for faster matching However, MeasureThat.net's approach provides a convenient and standardized way to compare the performance of different methods in a controlled environment.
Related benchmarks:
RegEx.test vs. String.includes vs. String.match insensitive
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?