Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lazy Quantifier and non capturing group vs Greedy Quantifier with capturing group REGEX B@B
(version: 0)
Comparing performance of:
greedy capturing vs lazy non capturing
Created:
2 years ago
by:
Guest
Jump to the latest result
Tests:
greedy capturing
new RegExp("^([^./]+\\.)*slack.com").test("sub1.sub2.slack.com/");
lazy non capturing
new RegExp("^(:?[^./]+\\.)*?slack.com").test("sub1.sub2.slack.com/");
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
greedy capturing
lazy non capturing
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/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Browser/OS:
Chrome 121 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
greedy capturing
7256858.5 Ops/sec
lazy non capturing
7673621.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark definition and test cases to understand what is being tested. **Benchmark Definition** The benchmark definition consists of two parts: 1. **Regular Expression (REGEX) Syntax**: The script preparation code defines two REGEX patterns: * `new RegExp("^([^./]+\\.)*slack.com").test("sub1.sub2.slack.com/")` * `new RegExp("^(:?[^./]+\\.)*?slack.com").test("sub1.sub2.slack.com/")` These REGEX patterns are designed to match URLs that end with `.slack.com`. 2. **Quantifier Usage**: The benchmark defines two types of quantifiers: * Greedy capturing: `^([^./]+\\\\\.)*slack.com` + In this pattern, the `(.*?)` group matches any characters (including none) between the `.` and the domain name, using a greedy approach. * Lazy non-capturing: `^(:?[^./]+\\.)*slack.com` + In this pattern, the `(?:)` group matches any characters (including none) between the `.` and the domain name, using a lazy approach. **Options Compared** The benchmark compares two different approaches to match the URL patterns: 1. **Greedy Capturing**: The first REGEX pattern uses greedy capturing (`^([^./]+\\\\\.)*slack.com`). This approach matches as much of the string as possible between the `.` and the domain name, but may lead to inefficient matching if the target string is shorter than expected. 2. **Lazy Non-Capturing**: The second REGEX pattern uses lazy non-capturing (`^(:?[^./]+\\.)*slack.com`). This approach matches the least amount of characters between the `.` and the domain name, which can lead to more efficient matching if the target string is shorter than expected. **Pros and Cons** Here are some pros and cons for each approach: Greedy Capturing: Pros: May match longer strings due to greedy behavior. Cons: Can be inefficient when the target string is shorter than expected. Lazy Non-Capturing: Pros: More efficient when the target string is shorter than expected. Cons: May not match longer strings due to lazy behavior. **Library and Purpose** None of the REGEX patterns use a specific library. The built-in `RegExp` object in JavaScript is used for both patterns. **Special JS Feature or Syntax** The benchmark uses a special syntax feature called "raw" URLs, which are represented by the `sub1.sub2.slack.com/` URL string. This is likely used to test the REGEX pattern's behavior on specific input data. **Other Alternatives** If you wanted to implement this benchmark in your own tooling, you could consider using a similar approach with different quantifier strategies or testing other types of REGEX patterns. Some alternatives include: * Using a different REGEX engine, such as PCRE (Perl-Compatible Regular Expressions) or the JavaScript `RegExp` engine's alternatives. * Testing the performance of different caching mechanisms for REGEX patterns. * Adding more test cases to cover additional scenarios, such as edge cases or specific character sets. Keep in mind that this benchmark is specifically designed for measuring the performance difference between two approaches using a particular REGEX pattern. If you were to modify it, you might need to adjust the approach and implementation accordingly.
Related benchmarks:
Regexp creation vs memoization
RegExp constructor vs literal vs premade, constructing in function, inline the test
RegEx.test vs. String.includes larger
Regex vs split/join to extract middle value
RegExp constructor vs literals, with variations
Comments
Confirm delete:
Do you really want to delete benchmark?