Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Faster regex to split a string into runs of similar characters?

by BrowserUk (Patriarch)
on Nov 21, 2016 at 10:43 UTC ( [id://1176236]=note: print w/replies, xml ) Need Help??


in reply to Re: Faster regex to split a string into runs of similar characters?
in thread Faster regex to split a string into runs of similar characters?

If you want to match all 256 byte values, you'll need the /s modifier.

Yes. /s not /m; I always mix those two up.

why are you using look-ahead assertions? Isn't /((.)\2+)/g stricly identical to your regex?

No. That won't match a single character 'run'.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re^2: Faster regex to split a string into runs of similar characters?

Replies are listed 'Best First'.
Re^3: Faster regex to split a string into runs of similar characters?
by Eily (Monsignor) on Nov 21, 2016 at 10:50 UTC
    No. That won't match a single character 'run'.

    Right. /((.)\2*)/g does though, and this time it is faster (by 12% on my computer).

      /((.)\2*)/g does though,

      Huh:) How did I missed that?!

      ... faster (by 12% on my computer).

      Only 4% difference on mine under 5.10 or 5.22:

      ## this 5.10 [0]{} Perl> cmpthese -1,{a=>q[ 1 while $s =~ m[((?=(.))\2+)]sg;],b=>q[ +1 while $s =~ m[((.)\2*)]sg;] };; Rate a b a 204/s -- -4% b 212/s 4% -- [0]{} Perl> cmpthese -1,{a=>q[ 1 while $s =~ m[((?=(.))\2+)]sg;],b=>q[ +1 while $s =~ m[((.)\2*)]sg;] };; Rate a b a 204/s -- -4% b 212/s 4% -- [0]{} Perl> C:\test>\Perl22\bin\perl.exe \Perl22\bin\p1.pl [0]{} Perl> $s = join'', map{ chr( 65+rand(26) ) x rand( 100 ) } 1 .. +1000;; [0]{} Perl> cmpthese -1,{a=>q[ 1 while $s =~ m[((?=(.))\2+)]sg;],b=>q[ +1 while $s =~ m[((.)\2*)]sg;] };; Rate a b a 229/s -- -3% b 235/s 3% -- [0]{} Perl> cmpthese -1,{a=>q[ 1 while $s =~ m[((?=(.))\2+)]sg;],b=>q[ +1 while $s =~ m[((.)\2*)]sg;] };; Rate a b a 229/s -- -4% b 238/s 4% --

      A small, but consistent gain. Thanks.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
      In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-04-18 21:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found