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:
sub rosetta_code_new { my ( $str ) = @_; my ( @pal, %seen ); for my $n ( 0 .. length( $str ) - 1 ) { for my $m ( 1 .. length( $str ) - $n ) { my $strpal = substr $str, $n, $m; push @pal, $strpal if $strpal eq reverse $strpal and not $seen{ $strpal } ++ } } return @pal }
And:
Rate rosetta eertree eertree 1159/s -- -27% rosetta 1584/s 37% --
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:
Rate rosetta eertree rosetta 387/s -- -31% eertree 565/s 46% --
I won't publish/compare with "my" recursive regex solution, it's slower. Not "orders of magnitude" neither, but, yeah, slow.
In reply to Re^2: Possessive sub-pattern with non-greedy content + recursion: WHY does this work??
by Anonymous Monk
in thread Possessive sub-pattern with non-greedy content + recursion: WHY does this work??
by Anonymous Monk
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |