in reply to qr//i versus m//i

Any suggestions?

Don't worry about it (ignore the benchmark)

See about m{(?i)$regex} option and see inside ack

Replies are listed 'Best First'.
Re^2: qr//i versus m//i ( qr slow )
by Anonymous Monk on Feb 21, 2014 at 19:38 UTC

    See also Re: Multiple Regex evaluations or one big one?

    Also if you use

    my $str1 = my $str2 = my $str3 = my $str4 = my $str = 'очень длинная строка ' x 10; ... 'qr//i+m//' => q{ $str1 =~ /$re_i/; return; }, 'qr//+m//i' => q{ $str2 =~ /$re/i; return; }, 'qr//+m//' => q{ $str3 =~ /$re/; return; }, 'qr' => q{ $str4 =~ $re; return; },
    You get (warning: too few iterations for a reliable count)

    If you my $count = -3; you get Timing is consistently zero in estimation loop, cannot benchmark. N=134217728

    What this means? don't worry about it :)

      Hah, another old benchmark i had laying around
      #!/usr/bin/perl -- use strict; use warnings; use Benchmark 'cmpthese'; my @small = 1; cmpthese( 500_000, { '__' => sub { for my $line ( @small ){ next if $line !~ /\s+(-?\d+\.\d+)\s+(-?\d+\.\d+)/; } return; }, '/_'.$].'_/' => eval ' sub { for my $line ( @small ){ next if $line !~ /'. qr{\s+(-?\d+\.\d+)\s+(-?\d+\.\d+)} # 5.12.2 (?-xism: # 5.14.1 (?^: .'/; } return; } ', 'qr' => sub { my $re = qr{\s+(-?\d+\.\d+)\s+(-?\d+\.\d+)}; for my $line ( @small ){ next if $line !~ $re; } return; }, '/qr/' => sub { my $re = qr{\s+(-?\d+\.\d+)\s+(-?\d+\.\d+)}; for my $line ( @small ){ next if $line !~ /$re/; } return; }, ## 2014-02-21-11:33:11 'qr,//o' => do { our $gre = qr{\s+(-?\d+\.\d+)\s+(-?\d+\.\d+)}; sub { for my $line ( @small ){ next if $line !~ /$gre/; } return; }; }, }); __END__ Rate /qr/ qr qr,//o __ /_ +5.016001_/ /qr/ 198807/s -- -0% -48% -71% + -75% qr 198807/s 0% -- -48% -71% + -75% qr,//o 385505/s 94% 94% -- -43% + -52% __ 680272/s 242% 242% 76% -- + -15% /_5.016001_/ 800000/s 302% 302% 108% 18% + --