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


In reply to Re^2: ^N.*(?!00$) by tlm
in thread ^N.*(?!00$) by ady

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.