|
|
| Don't ask to ask, just ask | |
| PerlMonks |
Re: Why is "any" slow in this case?by ikegami (Patriarch) |
| on Jul 28, 2025 at 15:40 UTC ( [id://11165833]=note: print w/replies, xml ) | Need Help?? |
|
As for ugly vs ugly_cr, $1 is a magic variable. Everytime you read from it, it gets repopulated (the matched substring is copied into it from the matched string) and subsequently numified. ugly_cr is faster because it cuts down the number of times that happens by four. As for any vs any_cr, The anon subs in any don't capture any variables, but the ones in any_cr capture two. Introducing capturing adds overhead that's more expensive than the magic on $1. Update: Added "and subsequently numified". Update: Confirmed that the overhead from capturing is the culprit, and adjusted the text appropriately. I confirmed this by changing all four any { ... } to any { $data; ... }. With this change, any becomes slower than any_cr.
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||