Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: most terse regex match count

by haukex (Archbishop)
on May 18, 2019 at 19:13 UTC ( [id://11100228]=note: print w/replies, xml ) Need Help??


in reply to Re^2: most terse regex match count
in thread most terse regex match count

Quick thought to reduce capturing: m|()A|gs?

Unfortunately it seems the extra capture group actually slows things down - no matter how much I fiddle with the parameters at the top, nocapt is always about 2x as fast:

#!/usr/bin/env perl use warnings; use strict; use Benchmark qw/cmpthese/; my $count = 1000; my $match = 'ABC'x20; my $space = 'xAz'x100; my $str = ( $space.$match x $count ) . $space; cmpthese(-3, { nocapt => sub { die unless $count == ( () = $str =~ m|\Q$match|gs ); }, withcapt => sub { die unless $count == ( () = $str =~ m|()\Q$match|gs ); }, }); __END__ Rate withcapt nocapt withcapt 4264/s -- -50% nocapt 8596/s 102% --

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2024-04-19 15:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found