Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
TEST match vs exec on safari
(version: 2)
Comparing performance of:
regex full vs regex part (WORST CASE) vs regex part (BEST CASE) vs Match
Created:
4 years ago
by:
Registered User
Jump to the latest result
Tests:
regex full
/^((['])((?:\\.|[^'])+?)(')|(['])(.*)(')|(["])((?:\\.|[^"])+?)(")|([`])((?:\\.|[^`])+?)(`))/.exec("`SELECT (1);`")
regex part (WORST CASE)
/^((['])((?:\\.|[^'])+?)('))/.exec("`SELECT (1);`"); /^((['])(.*)('))/.exec("`SELECT (1);`"); /^((["])((?:\\.|[^"])+?)("))/.exec("`SELECT (1);`"); /^(([`])((?:\\.|[^`])+?)(`))/.exec("`SELECT (1);`");
regex part (BEST CASE)
const r = /^(([`])((?:\\.|[^`])+?)(`))/.exec("`SELECT (1);`"); if(r) { return; } /^((['])((?:\\.|[^'])+?)('))/.exec("`SELECT (1);`"); /^((['])(.*)('))/.exec("`SELECT (1);`"); /^((["])((?:\\.|[^"])+?)("))/.exec("`SELECT (1);`");
Match
"`SELECT (1);`".match(/^(([`])((?:\\.|[^`])+?)(`))/)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
regex full
regex part (WORST CASE)
regex part (BEST CASE)
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):
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: 1. **`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);"`. 2. **`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. 3. **`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. 4. **`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: * Using `exec()` vs. `match()` * Anchoring (`^` and `$`) in the regular expression * Optimizing for guaranteed matches (`if(r) { return; }`) * Testing worst-case and best-case scenarios **Pros and Cons:** 1. **Using `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. 2. **Anchoring (`^` and `$`) in the regular expression**: * Anchors can improve performance by reducing the number of characters that need to be matched, but may also increase complexity and slow down execution if not used carefully. 3. **Optimizing for guaranteed matches (`if(r) { return; }`)**: * This optimization can reduce unnecessary work when a match is guaranteed, but may add overhead due to the conditional statement. **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: * Using a more efficient algorithm for regular expression matching * Optimizing the regular expression itself to reduce complexity and overhead * Comparing the performance of different JavaScript engines (e.g., V8, SpiderMonkey) or browsers These alternatives are not explicitly tested in this benchmark, but may be worth exploring for further optimization or performance improvement.
Related benchmarks:
querySelector by attribute (partial matching) VS getElementById
querySelector by attribute (partial matching) VS getElementById VS getElementsByTagName
test matches vs querySelectorAll
getComputedStyle vs matchMedia (javi 2)
RegEx.exec vs StrRaasdhakshjding.match
Comments
Confirm delete:
Do you really want to delete benchmark?