in reply to Why is "any" slow in this case?
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Why is "any" slow in this case?
by Anonymous Monk on Jul 29, 2025 at 07:12 UTC | |
by ikegami (Patriarch) on Jul 29, 2025 at 11:50 UTC | |
by Anonymous Monk on Jul 31, 2025 at 21:33 UTC | |
|
Re^2: Why is "any" slow in this case?
by LanX (Saint) on Jul 28, 2025 at 15:51 UTC | |
by ysth (Canon) on Jul 28, 2025 at 16:56 UTC | |
by ikegami (Patriarch) on Jul 28, 2025 at 16:45 UTC | |
by LanX (Saint) on Jul 28, 2025 at 16:54 UTC | |
by ikegami (Patriarch) on Jul 28, 2025 at 18:18 UTC | |
by LanX (Saint) on Jul 28, 2025 at 20:33 UTC | |
|