💾 Archived View for thrig.me › blog › 2023 › 10 › 31 › notnextchar.pl captured on 2023-11-14 at 07:56:03.

View Raw

More Information

-=-=-=-=-=-=-

#!/usr/bin/perl
# notnextchar.pl - benchmark "capture before first b" regular expressions
use 5.36.0;
use Benchmark 'cmpthese';

my $s = ( 'a' x 9999 ) . 'but not these bytes';

cmpthese -5,
  { dotplus => sub { $s =~ /^(.+)b/   },
    dotplqu => sub { $s =~ /^(.+?)b/  },
    notnext => sub { $s =~ /^([^b]+)/ },
  }