Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
RegExp: negative vs lazy (non-greedy)
(version: 0)
Comparing performance of:
Negative vs Lazy (non-greedy)
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
/* André Antunes da Cunha - hello world! */ var negative = /<[^>]*>/g; var lazy = /<.*?>/g; var input = "hello <01> hello <02> hello <03> hello <04> hello <05> hello <06> hello <07> hello <08> hello <09> hello <10> " + "hello <11> hello <12> hello <13> hello <14> hello <15> hello <16> hello <17> hello <18> hello <19> hello <20> " + "hello";
Tests:
Negative
[...input.matchAll(negative)]; /* Array.from(input.matchAll(negative)); */
Lazy (non-greedy)
[...input.matchAll(lazy)]; /* Array.from(input.matchAll(lazy)); */
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Negative
Lazy (non-greedy)
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:137.0) Gecko/20100101 Firefox/137.0
Browser/OS:
Firefox 137 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Negative
1105535.1 Ops/sec
Lazy (non-greedy)
1138304.8 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON and explain what's being tested in this JavaScript microbenchmark. **Benchmark Definition** The benchmark is designed to compare the performance of two regular expression (RegExp) patterns: one with a negative lookahead (`negative`) and another with a lazy (non-greedy) quantifier (`lazy`). **Options Compared** Two options are compared: 1. **Negative Lookahead**: This pattern uses a negative lookahead assertion (`<[^>]*>`) to match any character that is not `>` (the closing angle bracket). The `g` flag at the end of the pattern makes it global, so it matches all occurrences in the input string. 2. **Lazy (Non-Greedy) Quantifier**: This pattern uses a lazy quantifier (`<.*?`) to match any character that is not `>`. The `?` quantifier makes the preceding character (in this case, `<`) as few times as possible, while still matching. **Pros and Cons of Each Approach** 1. **Negative Lookahead**: * Pros: Simple and straightforward pattern. * Cons: May lead to slower performance if the negative lookahead is not optimized by the browser's regex engine. 2. **Lazy (Non-Greedy) Quantifier**: * Pros: Often more efficient than positive quantifiers, as it allows the browser's regex engine to make educated guesses about the number of matches. * Cons: May require a deeper understanding of regular expression patterns and their behavior. **Library** There is no explicit library mentioned in the benchmark definition. However, the use of `matchAll` and `Array.from` suggests that the benchmark is targeting modern JavaScript environments (ES6+). **Special JS Feature or Syntax** This benchmark does not specifically test any special JavaScript features or syntax beyond regular expression patterns. **Other Considerations** When comparing these two approaches, it's essential to consider the following factors: * **Input String**: The input string used in this benchmark is a large sequence of HTML elements with varying levels of nesting. This may affect the performance of both patterns. * **Browser and Regex Engine**: Different browsers and regex engines may optimize or implement regular expressions differently, which can impact performance. **Alternatives** If you were to create an alternative benchmark for regular expression performance, you could consider testing other common scenarios, such as: 1. Matching a specific pattern in a large input string (e.g., `match()` vs. `matchAll()`). 2. Comparing the performance of different quantifiers (e.g., `+`, `*`, `?`) or character classes. 3. Testing the performance of regular expressions with Unicode characters or non-ASCII characters. Keep in mind that the choice of benchmark scenario ultimately depends on your specific use case and goals.
Related benchmarks:
String.match vs. RegEx.test1
RegEx.test vs. String.includes incasesensitive
Long regex test vs string includes
Longer regex test vs string includes
Regex tests Dani
Comments
Confirm delete:
Do you really want to delete benchmark?