in reply to Re: Why doesn't this regex work? (Solved!)
in thread Why doesn't this regex work? (Solved!)
Nice, doing the least amount of work is the fastest
#!/usr/bin/perl -- use Benchmark ':all'; my $orig = '105 106 107 108 109 110 111 112 113 220 221 223 100 101 198 199 200 201 298 299 300 301 398 399 400 401 1115 1116 1117 1118 1119 1120 1121 1122 1123 1200 1201 1202 1100 1101 1102 1198 1199 1200 1201 1202 1298 1299 1300 1301 12345 12346 12347 12348 12349 12450 12451 12453 12466 12467 12300 12301 12398 12399 12400 12401 12498 12499 12500 12501';;; print "$]\n"; exit Verify() if @ARGV; cmpthese( -3, { anoNa => \&anoNa , anoNb => \&anoNb , anoM => \&anoM , bukA => \&bukA , bukB => \&bukB , } ); sub anoNa { $_ = $orig; s[(\d+)\d\K\s(?=(??{$1+1})\d\s)]{\n}g; } sub anoNb { $_ = $orig; s[(?<=\s)(\d+)\d\K\s(?=(??{$1+1})\d\s)]{\n}g; +} sub anoM { $_ = $orig; s{ (\d) \d\d \K [^\n\S]+ (?! \d* \1 \d\d \b) + }{\n}xmsg; } sub bukA { $_ = $orig; s[(?<=\s)(\d+)\d\K\s(?=(\d+)\d\s)]{$1+1==$2 ? +qq[\n] : ' '}ge; } sub bukB { $_ = $orig; s[\b(\d+)\d\K\s(?=(\d+)\d\s)]{$1+1==$2 ? qq[\n +] : ' '}ge; } sub Verify { print "\n# anoNa \n", anoNa(),"\n"; print "$_\n\n"; print "\n# anoNb \n", anoNb(),"\n"; print "$_\n\n"; print "\n# anoM \n", anoM(),"\n"; print "$_\n\n"; print "\n# bukA \n", bukA(),"\n"; print "$_\n\n"; print "\n# bukB \n", bukB(),"\n"; print "$_\n\n"; } __END__
FWIW the outputs aren't identical but they're close enough :)5.016003 Rate anoNa anoNb bukA bukB anoM anoNa 461/s -- -59% -90% -90% -94% anoNb 1126/s 144% -- -76% -76% -85% bukA 4662/s 910% 314% -- -0% -40% bukB 4675/s 913% 315% 0% -- -40% anoM 7751/s 1580% 588% 66% 66% --
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Why doesn't this regex work? (?!bench)
by BrowserUk (Patriarch) on Aug 16, 2013 at 09:43 UTC |