in reply to Re: removing the white spaces
in thread removing the white spaces
You can probably speed up the "_r" versions a little by removing unnecessary "+"s. For example, change
to$str =~ s/\s+/ /g; $str =~ s/^\s+//; $str =~ s/\s+$//;
$str =~ s/\s+/ /g; $str =~ s/^\s//; $str =~ s/\s$//;
Update: The improvement is quite substantial. Without the +, it ties 3-sp for fastest for short strings, and it's 42% faster than second fastest for long strings.
Short string: Rate 3-sp_r 3-sp_r2 3-sp 3-sp_r 329182/s -- -14% -14% 3-sp_r2 382305/s 16% -- -1% 3-sp 384541/s 17% 1% -- Long string: Rate 3-sp 3-sp_r 3-sp_r2 3-sp 20911/s -- -12% -38% 3-sp_r 23687/s 13% -- -29% 3-sp_r2 33582/s 61% 42% --
|
|---|