in reply to Using substr to split a string scales as N^2 -- alternatives?
The best workaround I've found is to modify the string in-place by using the 4-arg substr. This effectively just adjusts a pointer and a couple of offsets, and so runs 1000x faster:
c:\test>TimeIt \perl\bin\perl.exe -e"$a = 'a' x 800_000; substr($a, 0, 1, '') while length($a);" Kernel: 0.00000 User: 0.26563 Total: 0.26563
Unfortunately, it isn't a good substitute for the lvalue ref problem.
|
---|