|
|
|
Clear questions and runnable code get the best and fastest answer |
|
| PerlMonks |
Re^2: Possessive sub-pattern with non-greedy content + recursion: WHY does this work??by Anonymous Monk |
| on Aug 05, 2025 at 23:41 UTC ( [id://11165965]=note: print w/replies, xml ) | Need Help?? |
|
Thanks, choroba, your module, blog post and linked paper look interesting. What follows isn't really on topic. I lamented here recently about Rosetta Perl snippets quality; here it is again. Sort of consolation for me (after dear ikegami was kind enough to enlighten me about near total lack of understanding about regexes), that there are people even sloppier. It's a bit surprising you bothered to benchmark against that code (give each and every advantage to your opponent, no?). To wit: (1) This sub uses package vars, the array grows an each call during benchmarking, kind of unfair position you put that contestant to, no? (2) It's a shock to see that all the innermost loop does is string reversing. (3) The condition in "if" is never true (4) the 2nd "for" gives the same result about half of the time because there's string overshoot beyond its length (5) I'd filter out duplicates as they appear instead of grepping later. Then:
And:
Not exactly the result as published, methinks. To be fair, your solution outpaces the above naive one if e.g. "10" is increased to "20", but still, not by orders of magnitude:
I won't publish/compare with "my" recursive regex solution, it's slower. Not "orders of magnitude" neither, but, yeah, slow.
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||||||||||||||||