Firstly, you omitted the other contender:
... sub lookbehind { my $x = shift; split '(?:(?<=[^#]####)|(?<=[^#]##)|(?<!#))[@]', $x; } C:\test>junk8 Subroutine Benchmark::mytime redefined at c:/Perl/lib/Benchmark.pm lin +e 459. Benchmark: timing 10000 iterations of lookbehind, rollahead, unroll ... lookbehind: 2.34183 wallclock secs ( 2.19 usr + 0.00 sys = 2.19 CPU) + @ 4570.38/s (n=10000) rollahead: 3.46343 wallclock secs ( 3.23 usr + 0.00 sys = 3.23 CPU) + @ 3092.15/s (n=10000) unroll: 3.51775 wallclock secs ( 3.33 usr + 0.02 sys = 3.34 CPU) + @ 2990.43/s (n=10000) Rate unroll rollahead lookbehind unroll 2990/s -- -3% -35% rollahead 3092/s 3% -- -32% lookbehind 4570/s 53% 48% --
Secondly, you didn't check your results. unroll and rollahead produce different results:
rollahead => @# #@## ##@ ##@## #@# # @# #@## ##@@# #@## ##@ +@# #@ ... unroll => @# #@## ##@ ##@## #@# @# #@## ##@@# #@## ##@@ +# #@# ...
And both sets are wrong! Any output that has an even number of #s preceding a @ (as with the 3rd, 4th etc. outputs above) is wrong. If you look back at the op, you'll see that any @s that persist into the results set are preceded by an odd number of ##s.
The results set from the fastest algorithm:
lookbehind => #@## ###@#### #####@ #####@#### ###@## # #@## + ###@#### ...
In reply to Re: Seeking Audience with the Perl Regex Droids...
by BrowserUk
in thread Seeking Audience with the Perl Regex Droids...
by mobiusinversion
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |