/^((['])((?:\\.|[^'])+?)(')|(['])(.*)(')|(["])((?:\\.|[^"])+?)(")|([`])((?:\\.|[^`])+?)(`))/.exec("`SELECT (1);`")
/^((['])((?:\\.|[^'])+?)('))/.exec("`SELECT (1);`");
/^((['])(.*)('))/.exec("`SELECT (1);`");
/^((["])((?:\\.|[^"])+?)("))/.exec("`SELECT (1);`");
/^(([`])((?:\\.|[^`])+?)(`))/.exec("`SELECT (1);`");
const r = /^(([`])((?:\\.|[^`])+?)(`))/.exec("`SELECT (1);`");
if(r) {
return;
}
/^((['])((?:\\.|[^'])+?)('))/.exec("`SELECT (1);`");
/^((['])(.*)('))/.exec("`SELECT (1);`");
/^((["])((?:\\.|[^"])+?)("))/.exec("`SELECT (1);`");
"`SELECT (1);`".match(/^(([`])((?:\\.|[^`])+?)(`))/)
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
regex full | |
regex part (WORST CASE) | |
regex part (BEST CASE) | |
Match |
Test name | Executions per second |
---|---|
regex full | 6601499.5 Ops/sec |
regex part (WORST CASE) | 5097436.0 Ops/sec |
regex part (BEST CASE) | 9311991.0 Ops/sec |
Match | 8691655.0 Ops/sec |
The provided JSON represents a set of benchmark tests for measuring the performance of JavaScript regular expression execution on different browsers and devices.
Test Cases:
There are four test cases:
regex full
: This test case measures the execution time of a regular expression that matches a string using the exec()
method with no anchors (^
and $
). The string to be matched is "SELECT (1);"
.regex part (WORST CASE)
: This test case measures the execution time of a regular expression that matches a substring within a larger string, starting from the beginning (^
) of the entire string. Again, the string to be matched is "SELECT (1);"
. The WORST CASE
designation suggests that this test case may hit performance bottlenecks or edge cases.regex part (BEST CASE)
: This test case measures the execution time of a regular expression that matches a substring within a larger string, but only if the matching is successful (if(r) { return; }
). The string to be matched is still "SELECT (1);"
. This test case appears to optimize for cases where the match is guaranteed.Match
: This test case measures the execution time of a regular expression that uses the match()
method instead of exec()
. Again, the string to be matched is "SELECT (1);"
.Options Compared:
The benchmark tests compare different approaches for executing JavaScript regular expressions:
exec()
vs. match()
^
and $
) in the regular expressionif(r) { return; }
)Pros and Cons:
exec()
vs. match()
:exec()
is generally faster, but may not support capturing groups or other advanced features.match()
provides more flexibility, but may be slower due to the overhead of compiling a regular expression.^
and $
) in the regular expression:if(r) { return; }
):Library Usage:
The test cases do not appear to use any external libraries or frameworks. The regular expressions are executed directly in JavaScript.
Special JS Features or Syntax:
None of the test cases explicitly use special JavaScript features or syntax beyond what is standard for JavaScript regular expression execution.
Alternative Approaches:
Other alternatives could include:
These alternatives are not explicitly tested in this benchmark, but may be worth exploring for further optimization or performance improvement.