in reply to Re: Re: Peeling the Peelings
in thread Peeling the Peelings
It's easy to optimize a bit, although it's still 20% slower than Aristotle's version :-(
The benchmark results are:my %cache = ('-1' => qr/([^\(\)]+)\)+\Z/); sub peel { my $str = shift; my $level = shift || 0; if (!exists $cache{$level}) { my $opening = '[^\(]+\(' x $level; my $closing = '\)' x $level; $cache{$level} = qr/\A$opening(.+?)$closing\Z/; } $str =~ $cache{$level}; return $1; }
Rate Fatvamp gjb bobn Aristotle Fatvamp 21155/s -- -14% -17% -28% gjb 24631/s 16% -- -3% -16% bobn 25523/s 21% 4% -- -13% Aristotle 29497/s 39% 20% 16% --
Best regards, -gjb-
|
|---|