or download this
$ perl -MBenchmark=cmpthese -wE'my$x=join" "=>"",("aaa")x5,"";say"s
+ourc: |$x|";sub splt{split" ",$x,1};sub rgx{$x=~s/^\s+//r};say "split
+: |",splt(),"|";say"regex: |",rgx(),"|";cmpthese(-2,{splt=>\&splt,rgx
+=>\&rgx})'
sourc: | aaa aaa aaa aaa aaa |
...
Rate rgx splt
rgx 3382502/s -- -58%
splt 7989872/s 136% --
or download this
$ perl -MBenchmark=cmpthese -wE'my$x=join" "=>"",("abc")x5,"";say"s
+ourc: |$x|";sub splt{split" ",reverse((split" ",(reverse$x),1)[0]),1;
+};sub rgx{$x=~s/^\s+//r=~s/\s+$//r};say "split: |",splt(),"|";say"reg
+ex: |",rgx(),"|";cmpthese(-2,{splt=>\&splt,rgx=>\&rgx})'
sourc: | abc abc abc abc abc |
...
Rate rgx splt
rgx 1047602/s -- -64%
splt 2915089/s 178% --