Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
RegEx.test vs. String.includes vs. String.match pr
(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 = "12 CACAUSD"; var regex = /USD/;
Tests:
RegEx.test
regex.test(string);
String.includes
string.includes("Hello");
String.match
string.match("Hello");
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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15
Browser/OS:
Safari 17 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
RegEx.test
9378333.0 Ops/sec
String.includes
13275682.0 Ops/sec
String.match
10522551.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the provided benchmark. **What is tested?** The provided benchmark tests three approaches to search for the string "USD" in a given string: 1. `RegEx.test()`: This method uses regular expressions (regex) to search for the specified pattern in the input string. 2. `String.includes()`: This method checks if the input string includes the specified substring. 3. `String.match()`: This method searches for the first occurrence of the specified pattern in the input string. **Options compared** The benchmark compares the performance of each approach across different browsers (Safari 17) and devices (Desktop). **Pros and Cons of each approach:** 1. **RegEx.test()** * Pros: + More flexible and powerful than `String.includes()` and `String.match()`. + Can perform complex searches with multiple patterns. * Cons: + May be slower due to the overhead of compiling regular expressions. 2. **String.includes()** * Pros: + Simple and lightweight, making it faster than regex-based approaches. + Suitable for simple substring matching tasks. * Cons: + Less flexible than regex-based approaches, as it only searches for exact matches. 3. **String.match()** * Pros: + Similar to `RegEx.test()` but with fewer features and less flexibility. + Can be faster than regex-based approaches due to its simpler implementation. * Cons: + Less powerful than `RegEx.test()` and may not support all regex features. **Library and purpose** None of the test cases use any external libraries. The tests are self-contained in terms of input strings, regex patterns, and JavaScript methods. **Special JS feature or syntax (none mentioned)** There is no mention of any special JavaScript features or syntax used in this benchmark. **Other alternatives** If you were to add additional approaches to the benchmark, some alternatives could be: * Using a dedicated string search library like `StringSearch` or ` regex-optimizations` * Implementing a custom search algorithm using a data structure like a trie * Using Web Workers to parallelize the search tasks However, these alternatives would likely require significant changes to the test setup and implementation. Overall, this benchmark provides a useful comparison of three common string search methods in JavaScript, highlighting their trade-offs in terms of flexibility, performance, and complexity.
Related benchmarks:
RegEx.test vs. String.includes vs. String.match insensitive
Case insensitive RegEx.test vs. String.includes when string doesn’t match
RegEx.test vs. String.includes incasesensitive
Longer regex test vs string includes
Comments
Confirm delete:
Do you really want to delete benchmark?