Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Asterisk character test
(version: 0)
Comparing performance of:
RegEx.test vs String.includes vs String.match
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var string = "*\n\u001e\rA*SI 6*6014*5000*DL00*1019*ZC02*7000*DLDA*I123*568\n*CSLA*TNAM*\nDDE*\nDAC*ARIA*DDFN*DAD\n*DGN\n*CAC\n*CBNO*E * \nD*DNON* \nDB*0831*009\n*BB01*1198*\nDBA*8312*24\nD*C2\nD*U065*n\nDA*BRN\n*AG60* B S*\nDAI*AN D*EGO\n*AJCA*DAK9*101 * *DCF\n*CGUS*\rZCZ*A01\r"; var regex = /A*SI/;
Tests:
RegEx.test
regex.test(string);
String.includes
string.includes("A*SI");
String.match
string.match("A*SI");
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:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and its test cases. **Benchmark Definition** The benchmark is measuring the performance of three different approaches for searching or checking if a specific string exists within another string: `regex.test()`, `string.includes()`, and `string.match()`. **Test Cases** 1. **RegEx.test**: This test case uses the `RegExp` object's `test()` method, which attempts to match the regular expression against the entire input string. 2. **String.includes**: This test case uses the `includes()` method, which checks if a specified value exists within a given string. 3. **String.match**: This test case uses the `match()` method, which searches for a regular expression in a string and returns an array of matches. **Library Used: RegExp** The `RegExp` object is used in the first test case (`RegEx.test`). The `RegExp` object provides a way to search for a pattern in a string. In this case, it's using a regular expression to match against the input string `string`. **JavaScript Features/Syntax Used** * None explicitly mentioned, but note that this benchmark is focused on the performance of these specific methods and does not delve into more advanced JavaScript features. **Comparison Options: Pros and Cons** The three methods have different approaches to searching or checking if a string exists within another: 1. **RegExp.test()**: * Pros: Can perform complex searches, supports negative lookaheads and assertions, and can be optimized for performance. * Cons: Can be slower than other methods due to its use of regular expressions and the overhead of compiling the regex pattern. 2. **String.includes()**: * Pros: Fast and efficient, as it uses a simple string comparison algorithm. * Cons: May not support complex searches or regular expressions, which can lead to slower performance for certain use cases. 3. **String.match()**: * Pros: Supports regular expressions, which can be useful for more complex searches. * Cons: Can be slower than `includes()` due to the overhead of compiling and executing the regex pattern. **Other Alternatives** If you need faster or more efficient string matching, consider using: 1. **Array.prototype.includes()**: Similar to `String.includes()`, but optimized for arrays. 2. **String.prototype.startsWith()** and **String.prototype.endsWith()**: Can be used in combination with `includes()` to check if a string starts with or ends with a certain substring. 3. **Regular expression APIs**: If you need more advanced features, consider using dedicated regular expression libraries like `lodash.regex` or `regex-js`. Keep in mind that the choice of method ultimately depends on your specific use case and performance requirements. For this benchmark, MeasureThat.net is providing a controlled environment for developers to compare the performance of these three methods. By running multiple executions per second, the benchmark provides a comprehensive picture of each method's performance under different conditions.
Related benchmarks:
Alphanumeric
Alphanumeric String
testquery
blackList vs regexp2 - expanded
regex vs js - not Alphanumeric String
Comments
Confirm delete:
Do you really want to delete benchmark?