Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Regexp Greedy vs lazy cost v2
(version: 0)
Comparing performance of:
Lazy & good string vs Lazy & bad string vs Greedy & good string vs Greedy & bad string
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
str = '§625865/25565❤ §225,000/25k Drill Fuel' badStr = '§c4994/4994❤ §b-25 Mana (§6Instant Transmission§b) §b2929/2929✎ §3200ʬ §70/3 Secrets' lazyRE = RegExp('^§[6c](\\d+)\\/(\\d+)❤(\\+§c\\d+.)?? +(?:§a(\\d+)§a❈ Defense|([^✎]*?))??(?: +§b(\\d+)\\/(\\d+)✎ +(?:Mana|§3(\\d+)ʬ))??(?: +(§[27].*))??$', 'g') greedyRE = RegExp('^§[6c](\\d+)\\/(\\d+)❤(\\+§c\\d+.)? +(?:§a(\\d+)§a❈ Defense|([^✎]*?))?(?: +§b(\\d+)\\/(\\d+)✎ +(?:Mana|§3(\\d+)ʬ))?(?: +(§[27].*))?$', 'g')
Tests:
Lazy & good string
lazyRE.test(str)
Lazy & bad string
lazyRE.test(badStr)
Greedy & good string
greedyRE.test(str)
Greedy & bad string
greedyRE.test(badStr)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Lazy & good string
Lazy & bad string
Greedy & good string
Greedy & bad string
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 benchmark and explain what is being tested. **Benchmark Overview** The benchmark compares the performance of two regular expression (RE) patterns: lazy and greedy. The goal is to determine which pattern performs better on strings with different characteristics. **Test Cases** There are four test cases: 1. **Lazy & good string**: The RE engine tests a good string (`badStr`) using a lazy pattern (`lazyRE`). 2. **Lazy & bad string**: The RE engine tests the same good string (`badStr`) using a lazy pattern (`lazyRE`), but with different flag settings. 3. **Greedy & good string**: The RE engine tests a good string (`str`) using a greedy pattern (`greedyRE`). 4. **Greedy & bad string**: The RE engine tests the same good string (`str`) using a greedy pattern (`greedyRE`), but with different flag settings. **Regular Expression Patterns** The lazy and greedy patterns differ in how they match strings: * Lazy pattern: The `g` flag at the end of the regular expression indicates that the engine should stop as soon as it has found one match. In other words, the engine will try to match as little of the string as possible before backtracking. * Greedy pattern: By default, the greedy pattern tries to match as much of the string as possible before backtracking. **Library** The benchmark uses the built-in `RegExp` object in JavaScript, which is a powerful regular expression engine. **Special Features/ Syntax** There are no special features or syntax used in this benchmark that would require specific knowledge or expertise. The focus is on comparing the performance of different RE patterns. **Pros and Cons of Different Approaches** Here are some pros and cons of using lazy versus greedy regular expression patterns: * Lazy pattern: + Pros: Reduces backtracking, which can improve performance. + Cons: May miss some matches if the engine doesn't try to match as much of the string. * Greedy pattern: + Pros: Matches more of the string before backtracking, which may lead to more matches. + Cons: Can lead to increased backtracking and decreased performance. **Benchmark Results** The benchmark results show that the lazy pattern performs better on good strings (which should have a low number of matches) compared to greedy patterns. However, on bad strings (with many potential matches), the greedy pattern performs slightly better. It's worth noting that the flag settings used in some of the test cases may affect the performance differences between lazy and greedy patterns.
Related benchmarks:
Regexp creation vs memoization
Define Regex inline vs not.
isMarkdownURL
Regex tests Dani
Comments
Confirm delete:
Do you really want to delete benchmark?