Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
String.includes() vs. String.matchAll (no match)
(version: 0)
Comparing performance of:
String.includes() vs String.matchAll()
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var string = 'vars.test asflkglsfsdfm;l; s;lfkg;sldf g;sd f; sd;fl ;lsd fg;lsd f;gdsfg s df;gl sdl;fgkl;sdkf gl;s df;gl s;dlfg;sdfg }}'; var startDelim = '{{'; var endDelim = '}}'; var matcher = new RegExp(`${startDelim}((?!${endDelim}).+?)${endDelim}`, 'g');
Tests:
String.includes()
string.includes(startDelim) && string.includes(endDelim);
String.matchAll()
string.matchAll(matcher);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
String.includes()
String.matchAll()
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/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
String.includes()
4285666.5 Ops/sec
String.matchAll()
2984228.8 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Overview** The provided JSON represents a JavaScript microbenchmarking test case on the MeasureThat.net website. The test compares the performance of two string-related methods: `String.includes()` and `String.matchAll()`. Specifically, it tests the execution time of each method when searching for a substring within a large, complex string that contains no matches. **Tested Options** The benchmark compares two options: 1. **`String.includes()`**: This method searches for an exact match of a given substring within a string. It returns `true` if the substring is found and `false` otherwise. 2. **`String.matchAll()`**: This method returns all non-overlapping matches of a regular expression pattern within a string as an array of strings. **Pros and Cons** **`String.includes()`**: Pros: * Simple, straightforward implementation * Fast execution time due to its iterative approach Cons: * May not be suitable for searching multiple substrings or complex patterns * Can be slow for large input strings if the substring is not found **`String.matchAll()`**: Pros: * Supports regular expressions with complex patterns and anchors * Returns all matches, allowing for iteration over results Cons: * Slower execution time compared to `String.includes()` * May require more memory allocation for storing match results **Library and Special JS Features** In this benchmark, the `RegExp` constructor is used to create a regular expression pattern. The `g` flag at the end of the pattern enables global matching, which allows the method to search for all matches in the string. No special JavaScript features or syntax are mentioned in this benchmark. **Alternatives** Other alternatives for comparing the performance of these two methods might include: * **Using a library**: A dedicated string manipulation library like Lodash or a regular expression engine like RegExpOptimized could provide optimized implementations for `String.includes()` and `String.matchAll()`. * **Using a different algorithm**: Alternative algorithms, such as using a Boyer-Moore or Knuth-Morris-Pratt search for exact matches or a more efficient string matching algorithm like Aho-Corasick. * **Testing with smaller input strings**: Using smaller input strings to reduce the impact of caching, page loading, and other external factors on benchmark results. Overall, this benchmark provides a simple and effective way to compare the performance of `String.includes()` and `String.matchAll()` in a controlled environment.
Related benchmarks:
String.includes() vs. String.matchAll
String.includes() vs. String.matchAll v2
RegEx.matchAll vs includes no match
RegEx.matchAll vs includes with match
Comments
Confirm delete:
Do you really want to delete benchmark?