Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.includes vs Regex.test
(version: 0)
Comparing performance of:
Array.includes vs Regex.test
Created:
4 years ago
by:
Guest
Jump to the latest result
Tests:
Array.includes
const isCeoLevel = ['CEO_STAR','CEO_STAR_CREATOR']; isCeoLevel.includes("CEO_STAR")
Regex.test
const isCeoLevel = /^(CEO_STAR|CEO_STAR_CREATOR)$/; isCeoLevel.test('CEO_STAR');
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Array.includes
Regex.test
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
9 months ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36
Browser/OS:
Chrome 138 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array.includes
58403500.0 Ops/sec
Regex.test
22794330.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested. **Benchmark Overview** The benchmark measures the performance difference between two approaches: 1. `Array.includes` 2. `Regex.test` **What is being tested?** In this case, we're testing the performance of checking if a string matches a specific pattern using either an array-based approach or a regular expression (regex) based approach. **Options compared:** * `Array.includes`: This method checks if an element exists in an array. In this benchmark, it's used to check if a string (`"CEO_STAR"` or `"CEO_STAR_CREATOR"` ) exists within the `isCeoLevel` array. * `Regex.test`: This method returns true if the entire regex pattern matches the given string. **Pros and Cons of each approach:** * `Array.includes`: + Pros: - Typically faster than using a regular expression (especially for small arrays) - Easier to read and maintain + Cons: - May require an array to be created upfront, which can lead to memory overhead - May not be as flexible as regex patterns * `Regex.test`: + Pros: - Highly flexible and powerful for complex pattern matching - Can be used for multiple purposes beyond just string checking (e.g., parsing, validation) + Cons: - Typically slower than using `Array.includes` - Can lead to increased memory usage due to regex compilation **Library/Language Features:** In the provided benchmark test cases, we can see that: * The `includes` method is used with an array (`isCeoLevel`) * The `test` method is used with a regular expression pattern (`^(CEO_STAR|CEO_STAR_CREATOR)$`) These methods are part of the JavaScript language itself and don't require any external libraries. **Special JS Features/ Syntax:** The benchmark uses the following special features/syntax: * The `/regex-pattern/` syntax for creating regular expressions. * The `test()` method for testing if a string matches a regex pattern. * The `includes()` method for checking if an element exists in an array. These are all standard JavaScript language features that don't require any external libraries or frameworks. **Other alternatives:** If you were to benchmark the performance of other approaches, some alternatives could be: * Using a library like RegEx.js or regex-testing library for more complex regex patterns * Implementing a custom search algorithm using a data structure like a Trie or a hash table * Using a different programming language or framework that provides built-in support for array-based or regex-based string matching However, these alternatives would likely require additional setup and infrastructure, and may not be directly comparable to the `Array.includes` and `Regex.test` methods in this specific benchmark.
Related benchmarks:
RegEx.test vs. String.includes vs. String.match vs Array.includes
RegExp.test() vs Array.includes()
RegEx vs Array.includes
RegEx vs Array.includes v2
regex.test vs. array.includes
Comments
Confirm delete:
Do you really want to delete benchmark?