Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
regex.test vs. array.includes
(version: 0)
Comparing performance of:
regex.test vs array.includes
Created:
one year ago
by:
Guest
Jump to the latest result
Tests:
regex.test
/%20|\s/.test('hello%20world')
array.includes
[' ', '%20'].some((s) => 'hello%20world'.includes(s))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
regex.test
array.includes
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.2 Safari/605.1.15
Browser/OS:
Safari 18 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
regex.test
379307392.0 Ops/sec
array.includes
20775902.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**What's being tested:** MeasureThat.net is testing the performance of two approaches to check if a string contains a specific pattern: 1. **Regular Expressions (`/regex.test`)**: Using the `/` syntax to define a regular expression, which checks if the input string matches the pattern. 2. **String inclusion using `array.includes`**: Using the `includes()` method on an array of characters that might be part of the target string. **Options comparison:** * **Regular Expressions (regex.test)**: + Pros: - Can match complex patterns, including character classes, anchors, and quantifiers. - Provides a more flexible way to check for patterns in strings. + Cons: - Can be slower than other methods due to the overhead of compiling and executing regular expressions. - May not be suitable for very large inputs or performance-critical applications. * **String inclusion using `array.includes`**: + Pros: - Fast and efficient, as it only requires iterating over a small array of characters. - Suitable for large inputs and high-performance applications. + Cons: - Limited to checking if the input string contains specific characters or patterns. - May not be suitable for more complex pattern matching. **Other considerations:** * **Character encoding**: The benchmark does not specify the character encoding used in the test cases. In practice, this could affect the performance of regular expression-based approaches, which may need to account for differences in Unicode character encodings. **Library and syntax usage:** Neither the individual test cases nor the benchmark definition explicitly use a JavaScript library or feature beyond the standard language features. **Special JS feature or syntax:** The benchmark does not make use of any special JavaScript features or syntax beyond the standard language features mentioned above. However, it's worth noting that modern JavaScript environments (e.g., ES6+) often provide additional features and optimizations for regular expressions. **Alternatives:** Other approaches to check if a string contains a specific pattern might include: * **String interpolation**: Using template literals or other string interpolation methods to search for patterns in strings. * **Substring matching**: Using the `indexOf()` or `lastIndexOf()` methods to find occurrences of a substring within a larger string. * **Regexp alternatives**: Depending on the specific requirements, alternative regex syntaxes like PCRE (Perl-Compatible Regular Expressions) might be used. Keep in mind that each approach has its strengths and weaknesses, and the choice of method ultimately depends on the specific use case and performance requirements.
Related benchmarks:
RegEx.test vs. String.includes vs. String.match vs Array.includes
RegEx.test vs Array.includes bench
RegEx vs Array.includes
RegEx vs Array.includes v2
Comments
Confirm delete:
Do you really want to delete benchmark?