Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
RegEx vs Array.includes v2
(version: 0)
Comparing performance of:
RegEx.test vs Array.includes
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var regex = /\d/; var arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
Tests:
RegEx.test
regex.test('1')
Array.includes
arr.includes('1');
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:
4 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
Browser/OS:
Chrome 143 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
RegEx.test
78391856.0 Ops/sec
Array.includes
159115136.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, compared, and considered. **Benchmark Overview** The benchmark is designed to compare the performance of two JavaScript methods: regular expression (RegExp) `test()` and array `includes(v2)` for searching a specific value ("1") within an array of digits. The goal is to determine which method is faster. **Comparison Options** There are only two options being compared: 1. **Regular Expression (`test()`)** * Pros: + Widely supported by most JavaScript engines. + Allows for more flexible pattern matching, not limited to simple value searches. * Cons: + Can be slower than native array methods due to the overhead of creating and executing a regular expression. 2. **Array `includes(v2)`** * Pros: + Native to JavaScript, optimized for performance by the engine. + Generally faster than RegExp for simple value searches. * Cons: + Not available in older browsers or JavaScript engines that don't support modern array methods. **Other Considerations** 1. **Library usage**: Neither of the options relies on a third-party library. 2. **Special JS feature or syntax**: The benchmark uses `v2` in `arr.includes()`, which refers to the second version of the `includes()` method, introduced in ECMAScript 2019 (ES10). This is not a special feature or syntax, but rather a specific implementation detail. 3. **Device and browser variations**: The benchmark includes data from different devices (Desktop) and browsers (Chrome 122), which helps to account for potential differences in performance. **Benchmark Preparation Code** The provided script preparation code sets up the necessary variables: * `regex`: Creates a new RegExp object with a pattern that matches any digit (`\\d`). * `arr`: Defines an array of digits (`'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'`). **Individual Test Cases** Each test case consists of a single benchmark definition, which is executed once: * The first test case, `RegEx.test`, calls the RegExp `test()` method on the prepared regex object with the value `'1'`. * The second test case, `Array.includes`, calls the array `includes()` method (specifically, version 2) on the prepared array with the same value `'1'`. **Latest Benchmark Result** The provided result shows the execution statistics for each test case across different devices and browsers. The results indicate that `Array.includes(v2)` is slightly faster than `RegEx.test()`, but the difference is relatively small. Keep in mind that these results may not be representative of your specific use cases or environments, as they are based on a single set of device and browser configurations.
Related benchmarks:
array.toString vs `${array}`
array.splice vs array.length
`Array.slice(0, N)` vs `Array.length = N` sd434332432
DTMF: array includes vs regex
array.length = 0 vs []
Comments
Confirm delete:
Do you really want to delete benchmark?