|
|
| Perl-Sensitive Sunglasses | |
| PerlMonks |
Re^2: Are beheaded strings known to be slow?by ikegami (Patriarch) |
| on Oct 10, 2025 at 15:22 UTC ( [id://11166457]=note: print w/replies, xml ) | Need Help?? |
|
That's what it is. Regex matching makes a copy of the scalar for use by $&, $1, etc. It uses the COW mechanism if possible. It doesn't for OOK scalars. After one pass of test1's loop:
After one pass of test2's loop:
That means a copy of the string buffer must have been made. By the end of the loop, a copy has been done 99,999 times (once per successful regex match). You can run into the same issue with foreign string buffers (e.g. a memory-mapped file). See why is Perl File::Map so slow compared to File::Slurp?
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||