Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
RegEx.test (with inline regex) vs. String.includes vs. String.match
(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!";
Tests:
RegEx.test
/Hello/.test(string);
String.includes
string.includes("Hello");
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:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
RegEx.test
45086504.0 Ops/sec
String.includes
163684736.0 Ops/sec
String.match
8903239.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON data and explain what is tested in this JavaScript microbenchmark. **Benchmark Overview** The benchmark compares three different approaches to check if a specific string ("Hello") exists within another string: 1. **Regex.test**: Uses regular expressions (regex) with the `test()` method. 2. **String.includes**: Uses the `includes()` method. 3. **String.match**: Uses the `match()` method. **Options Compared** The three options being compared are: * Regex.test: This approach uses regex patterns to search for a match in the string. + Pros: - Can be more flexible and powerful than other approaches. - Often faster than other methods for complex searches. + Cons: - Can be slower than other methods for simple searches. - Requires additional setup (regex pattern) and error handling. * String.includes: This approach uses the `includes()` method, which checks if a substring exists within another string. + Pros: - Fast and efficient, especially for simple searches. - Easy to use and understand. + Cons: - May not be suitable for complex searches or regex patterns. - Can be slower than other methods for large strings. * String.match: This approach uses the `match()` method, which returns an array of matches if a pattern exists in the string. + Pros: - Can be used to extract multiple matches from a single search. - Often faster than other methods for simple searches. + Cons: - May return false positives or incorrect results if not used carefully. - Can be slower than other methods for complex searches. **Libraries and Special Features** * None of the options use external libraries. However, `String.includes` is a built-in method in JavaScript. * No special JS features or syntax are being tested. All three options are standard JavaScript methods. **Other Alternatives** Some alternative approaches to these methods include: * Using `indexOf()` or `lastIndexOf()` instead of `includes()`. * Using `regex.exec()` instead of `test()`. * Using `substring()` or other string manipulation methods to achieve similar results. * Using a library like UglifyJS or other minification tools to optimize the performance of these methods. **Benchmark Preparation Code** The provided script preparation code is simple: ```javascript var string = "Hello world!"; ``` This sets up a test string that will be used for all three benchmark cases.
Related benchmarks:
RegEx.test vs. String.includes vs. String.match insensitive
RegEx.test vs. String.includes incasesensitive
Long regex test vs string includes
Longer regex test vs string includes
Comments
Confirm delete:
Do you really want to delete benchmark?