Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Why is "any" slow in this case?

by Anonymous Monk
on Jul 28, 2025 at 06:15 UTC ( [id://11165816]=note: print w/replies, xml ) Need Help??


in reply to Why is "any" slow in this case?

Generally speaking: Sub routines and iteration are slower than operations. So ugly is always going to be faster than any, unless the ugly operation gets absurdly large, probably 100's of numbers.

Secondly, every time you access $1 or $2, there is a check of the regexp context, its not just taking some already known value, which adds overhead. So _cr of assigning $1/$2 to a local variable should always end up faster compared to even 2 or 3 uses of $1/$2.

Replies are listed 'Best First'.
Re^2: Why is "any" slow in this case?
by LanX (Saint) on Jul 28, 2025 at 08:40 UTC
    > every time you access $1 or $2, there is a check of the regexp context,

    Could you please elaborate what this means, especially "regexp context"?

    It rings a bell, but this seems counter-intuitive with a read only value like $1.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

      If you use $1 and then Devel::Peek::Dump it, you will see the values you got stored in it, but that's all ephemeral; the next access will trigger the get magic again, which does a lot of work to get info from where the regex engine stashes it (and leaves it in the $1 SV so the remainder of that operation can use it).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2026-03-09 00:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.