Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
RegEx.test vs. String.includes vs. String.match db
(version: 0)
Comparing performance of:
RegEx.test vs String.includes vs String.match
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
var string = "Hello world!"; var regex = /Hello/;
Tests:
RegEx.test
regex.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:
2 days ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:151.0) Gecko/20100101 Firefox/151.0
Browser/OS:
Firefox 151 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
RegEx.test
65250828.0 Ops/sec
String.includes
2979089664.0 Ops/sec
String.match
40160616.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the explanation of what's being tested in this benchmark. **What is being tested?** The provided JSON represents a JavaScript microbenchmark that compares three different approaches to search for a substring in a string: 1. `RegEx.test()` 2. `String.includes()` 3. `String.match()` These functions are used to determine whether a specified pattern exists at the beginning of a string. **Options compared:** The benchmark is comparing the performance of these three approaches on a specific test case, where the input string is `"Hello world!"` and the search pattern is `/Hello/`. Here's what each approach does: * `RegEx.test()`: Tests whether the entire input string matches the regular expression. In this case, it will return true if the string starts with "Hello". * `String.includes()`: Returns true if the specified value (in this case, a substring) is present anywhere in the string. * `String.match()`: Returns an array containing the matched result and the index of the match if the pattern exists at the beginning of the string. **Pros and Cons:** Here are some pros and cons for each approach: * `RegEx.test()`: + Pros: Can be more efficient for simple regular expressions, as it only scans the input string once. + Cons: May not work correctly if the pattern is complex or has multiple groups, which can lead to slower performance. * `String.includes()`: + Pros: Simple and easy to use, making it a good choice for quick checks. It's also a built-in method in JavaScript, so it's likely to be optimized by the engine. + Cons: Can be slower than regular expression testing for complex patterns or large strings, as it requires iterating through the entire string. * `String.match()`: + Pros: Returns an array of matches, which can be useful in certain situations. It also has a built-in timeout mechanism to prevent excessive processing time. + Cons: May not work correctly if the pattern is empty or doesn't match anything, returning null instead. **Library and purpose:** None of these approaches rely on external libraries. However, it's worth noting that `String.includes()` uses the `indexOf()` method internally to find the index of the specified value in the string. **Special JavaScript feature or syntax:** There are no special JavaScript features or syntax used in this benchmark. The use of regular expressions and built-in methods like `includes()` and `match()` are standard JavaScript constructs. **Other alternatives:** If you needed a more complex search pattern, you might consider using: * `String.prototype.replace()` with a callback function to replace the matched value * A dedicated library for string matching or regular expression processing However, these alternatives would likely incur performance overhead and may not be as straightforward to use as `RegEx.test()`, `String.includes()`, and `String.match()`.
Related benchmarks:
RegEx.test vs. String.includes vs. String.match insensitive
RegEx.test (with inline regex) vs. String.includes vs. String.match
Long regex test vs string includes
Longer regex test vs string includes
Comments
Confirm delete:
Do you really want to delete benchmark?