Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Re^2: meaning of /o in regexes

by BrowserUk (Pope)
on Dec 06, 2002 at 17:00 UTC ( #218100=note: print w/ replies, xml ) Need Help??


in reply to Re^2: meaning of /o in regexes
in thread meaning of /o in regexes

Thankyou diotalevi++. That is exactly the sort of answer I was looking for and it confirms my suspicions based on some fairly dodgey benchmarking.

No matter how hard I tried to isolate the benefits of qr//'ing or /o'ing, those benefits always seemed to disappear whenever I attempted to combine one or more pre-compiled regexes with each other or with some non-compiled stuff. In fact, I sometimes detected a penalty from using pre-compiled regexes other than stand-alone, though the differences were too small to quantify with any accuracy.


Okay you lot, get your wings on the left, halos on the right. It's one size fits all, and "No!", you can't have a different color.
Pick up your cloud down the end and "Yes" if you get allocated a grey one they are a bit damp under foot, but someone has to get them.
Get used to the wings fast cos its an 8 hour day...unless the Govenor calls for a cyclone or hurricane, in which case 16 hour shifts are mandatory.
Just be grateful that you arrived just as the tornado season finished. Them buggers are real work.


Comment on Re: Re^2: meaning of /o in regexes
Re^4: meaning of /o in regexes
by diotalevi (Canon) on Dec 06, 2002 at 17:12 UTC

    I looked even further and the get magic (see sv.c Perl_sv_2pv and seek to the "Regexp" section) associated with stringifying a qr regex is actually pretty cheap. I'd guess any real performance loss is just from having to compile a regex more than once which unless you are doing some monster regex... isn't all that much of an issue.

    __SIG__ use B; printf "You are here %08x\n", unpack "L!", unpack "P4", pack "L!", B::svref_2object(sub{})->OUTSIDE;

      The task that started me on the quest for speed was indeed a monster regex, it was also being called many times in a tight loop. As the regex was essentially repetitious, I originally thought that compiling the base regex with qr// and then using that in conjuction with a repeat count and the none repeating elements also compliled with /o might leach some benefits, but the reverse was true. I settled for programically generating the regex (using x n) into a single large regex and then compiling it with qr// (which appeared to give some slight performance benefit over /o). This was possibly due to the fact that when compiled with qr//, you can use the resultant variable directly ($string =~ $compiled_re) rather than needing to embed it within an m// operator (m/$compiled_re/). Maybe its slightly quicker to execute the former than the latter? The difference seemed significant enough to make it worthwhile..


      Okay you lot, get your wings on the left, halos on the right. It's one size fits all, and "No!", you can't have a different color.
      Pick up your cloud down the end and "Yes" if you get allocated a grey one they are a bit damp under foot, but someone has to get them.
      Get used to the wings fast cos its an 8 hour day...unless the Govenor calls for a cyclone or hurricane, in which case 16 hour shifts are mandatory.
      Just be grateful that you arrived just as the tornado season finished. Them buggers are real work.

        You are slightly wrong: <code$qr = qr/./; $qr =~ m/$qr/; $qr =~ $qr;</code> is exactly identical. Again, some opcode info to illuminate. It also yields the slightly interesting form $text = 'abcd'; $text =~ qr/./ but then... maybe that's not quite normal ;-)

        i <@> leave[t1] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 5 qr.pl:1) v ->3 5 <2> sassign vKS/2 ->6 3 </> qr(/./) s ->4 - <1> ex-rv2sv sKRM*/1 ->5 4 <> gvsv s ->5 6 <;> nextstate(main 5 qr.pl:2) v ->7 >> Here you see the $qr =~ m/$qr/ form b </> match() vKS ->c - <1> ex-rv2sv sK/1 ->8 7 <> gvsv s ->8 a <|> regcomp(other->b) sK/1 ->b 8 <1> regcreset sK/1 ->9 - <1> ex-rv2sv sK/1 ->a 9 <> gvsv s ->a >> And here you see the $qr =~ $qr form c <;> nextstate(main 5 qr.pl:3) v ->d h </> match() vKS ->i - <1> ex-rv2sv sK/1 ->e d <> gvsv s ->e g <|> regcomp(other->h) sK/1 ->h e <1> regcreset sK/1 ->f - <1> ex-rv2sv sK/1 ->g f <> gvsv s ->g
        __SIG__ use B; printf "You are here %08x\n", unpack "L!", unpack "P4", pack "L!", B::svref_2object(sub{})->OUTSIDE;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2014-12-25 00:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (159 votes), past polls