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:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var appState = "active"; var regex = /inactive|background/; var arr = ['inactive', 'background'];
Tests:
RegEx.test
regex.test(appState);
Array.includes
arr.includes(appState);
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:
6 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36
Browser/OS:
Chrome 142 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
RegEx.test
50412264.0 Ops/sec
Array.includes
12594884.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the explanation of the provided benchmark. **What is being tested?** The test measures the performance difference between two approaches: using regular expressions (regex) with `test()` function and using array methods (`includes()`). **Options being compared:** 1. **Regex with `test()`**: This approach uses a regex pattern to match against the input string `appState`. The `test()` method returns a boolean value indicating whether the pattern matches. 2. **Array with `includes()`: This approach checks if the input string `appState` is included in the array `arr`. **Pros and Cons of each approach:** 1. **Regex with `test()`**: * Pros: Can be more flexible, as regex patterns can handle complex matching requirements. * Cons: May be slower than simple array methods due to the overhead of compiling and executing the regex pattern. 2. **Array with `includes()`**: * Pros: Fast and lightweight, as it uses a native JavaScript method that is optimized for performance. * Cons: Limited to exact string matching; may not handle complex cases like regex. In general, regex can be more powerful but also slower due to the overhead of compiling and executing the pattern. Array methods are often faster and more lightweight, but may not offer the same level of flexibility as regex. **Library used in the test case:** None, this benchmark does not use any external libraries. **Special JS feature or syntax used:** There are no special features or syntax used in this benchmark, as it only relies on standard JavaScript functionality.
Related benchmarks:
RegEx.test vs Array.includes (Lowercase)
RegEx.match vs Array.includes
array.some vs regex.test
RegEx.test vs Array.includes -- 3 options
Comments
Confirm delete:
Do you really want to delete benchmark?