in reply to Re: ^N.*(?!00$)
in thread ^N.*(?!00$)

OK, thanks to ikegami's help, I've fixed the benchmarking code. Here are the results:

# The suffix +/- correspond to "matching" and "non-matching" input, # respectively. # input length: 7 Rate ?<!- ?!+ ?<!+ ?!- ?<!- 583158/s -- -38% -54% -55% ?!+ 945231/s 62% -- -25% -27% ?<!+ 1262619/s 117% 34% -- -2% ?!- 1286220/s 121% 36% 2% -- # input length: 10 Rate ?<!- ?!+ ?<!+ ?!- ?<!- 220554/s -- -49% -63% -64% ?!+ 430349/s 95% -- -28% -31% ?<!+ 601510/s 173% 40% -- -3% ?!- 619376/s 181% 44% 3% -- # input length: 10000 Rate ?<!- ?!+ ?!- ?<!+ ?<!- 342/s -- -91% -99% -99% ?!+ 3864/s 1029% -- -86% -86% ?!- 26795/s 7730% 593% -- -6% ?<!+ 28417/s 8204% 635% 6% --
The differences between first and second place are not significant (different runs of the same benchmarking script would yield different relative ordering). The differences between 2nd and 3rd place, and between 3rd and 4th place are significant, though. The results are not conclusive. Negative look-ahead clearly beats positive look-ahead when the input matches, but the opposite is true when the input doesn't match.

use strict; use warnings; use Benchmark 'cmpthese'; my $sz = ( shift || 10 ) - 4; our $match = 'N' . 'x' x $sz . '001'; our $nomatch = 'N' . 'x' x $sz . '000'; print '# input length: ', length( $match ), $/; cmpthese( -1, { '?!+' => '$::match =~ /^N(?!.*00$).*$/', '?!-' => '$::nomatch =~ /^N(?!.*00$).*$/', '?<!+' => '$::match =~ /^N.*(?<!00$)$/', '?<!-' => '$::nomatch =~ /^N.*(?<!00$)$/', } ); __END__

the lowliest monk