Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: qr//i versus m//i ( qr slow )

by Anonymous Monk
on Feb 21, 2014 at 19:38 UTC ( [id://1075772]=note: print w/replies, xml ) Need Help??


in reply to Re: qr//i versus m//i
in thread qr//i versus m//i

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 :)

Replies are listed 'Best First'.
Re^3: qr//i versus m//i ( benchmark.qr.versus.inline.pl eval )
by Anonymous Monk on Feb 21, 2014 at 19:46 UTC
    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% + --

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1075772]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-20 02:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found