Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
RegEx.test vs. String.includes vs. String.match-Fork
(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 = 'https://langehair.com/pages/le-duo-plp-fb' var regex = /\/pages\/le-duo-plp-fb/ var segment = '/pages/le-duo-plp-fb'
Tests:
RegEx.test
regex.test(string);
String.includes
string.includes(segment);
String.match
string.match(segment);
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 years ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0
Browser/OS:
Firefox 121 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
RegEx.test
49650084.0 Ops/sec
String.includes
56661664.0 Ops/sec
String.match
20585702.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the benchmark and explain what's being tested. **Benchmark Description:** The goal of this benchmark is to compare the performance of three string searching methods: 1. `RegEx.test()` 2. `String.includes()` 3. `String.match()` (with a custom implementation, as indicated by the "Fork" suffix) **What are we comparing?** * **`RegEx.test()`**: This method is part of the JavaScript RegExp object and tests whether a string matches a regular expression. * **`String.includes()`**: This method checks if a string contains a specified value. * **`String.match()` (with a custom implementation)**: This method returns an array containing the first occurrence of a pattern in a string. The "Fork" suffix suggests that this implementation is not part of the standard JavaScript `String.match()` method, but rather a custom implementation. **Pros and Cons of each approach:** * **`RegEx.test()`**: + Pros: Highly optimized for performance, takes into account word boundaries, and can handle complex regular expressions. + Cons: May be overkill for simple string matching, requires creating a RegExp object, and can be slower than other methods for very short strings. * **`String.includes()`**: + Pros: Simple and efficient, uses optimized internal implementation, and is relatively fast. + Cons: May not work as expected if the search value is not a string or is a regular expression (though this is not typically a problem in practice). * **`String.match(Fork)`**: This custom implementation is likely slower than the standard `String.match()` method due to its additional logic. However, it provides more control over the matching process. **Other considerations:** * The benchmark uses Firefox 121 as the test browser, which may have optimized string searching performance. * The "Desktop" device platform and Linux operating system are used in all tests, which may also impact results. * The number of executions per second (ExecutionsPerSecond) is used to compare performance across browsers. **Libraries and special JS features:** No external libraries are mentioned in the benchmark setup code. However, `String.includes()` uses a built-in method that relies on internal optimization and optimization for performance. The "Fork" suffix indicates that a custom implementation of `String.match()` is being used, which might require additional expertise or knowledge to understand its behavior. In summary, this benchmark compares the performance of three string searching methods: `RegEx.test()`, `String.includes()`, and a custom `String.match(Fork)` implementation. The results will help determine which method is most efficient for specific use cases.
Related benchmarks:
RegEx.test vs String.includes vs String.indexOf
Regex vs split/includes
RegEx.test vs. String.includes vs. String.match 2
RegEx.test vs. String.includes checking if https:// or http:// exists
Comments
Confirm delete:
Do you really want to delete benchmark?