in reply to Using substr to split a string scales as N^2 -- alternatives?
Or even s/.//s; Either will trigger an optimization that just adjusts the effective start of the string buffer without moving the data at all (when removing characters from the start of the string).$ time perl -e '$a = "a" x 50_000; substr($a, 0, 1, "") while length($ +a);' real 0m0.016s user 0m0.012s sys 0m0.008s ysth@cat:~$ time perl -e '$a = "a" x 100_000; substr($a, 0, 1, "") whi +le length($a);' real 0m0.029s user 0m0.024s sys 0m0.004s ysth@cat:~$ time perl -e '$a = "a" x 200_000; substr($a, 0, 1, "") whi +le length($a);' real 0m0.041s user 0m0.036s sys 0m0.004s
|
---|