in reply to Re^3: Unsuccessful stat on file test
in thread Unsuccessful stat on file test
Using a simple Benchmark example:
$ perl -le' use Benchmark q/cmpthese/; my @data = map { join( "", map { ( "a" .. "z" )[ rand 26 ] } 1 .. 10 + + rand( 10 ) ) . "\n" } 1 .. 1_000; cmpthese -10, { plus => sub { my @temp = @data; s/\s+$// for @temp; return @temp; }, star => sub { my @temp = @data; s/\s*$// for @temp; return @temp; } } ' Rate star plus star 336/s -- -66% plus 992/s 196% -- $ perl -le' use Benchmark q/cmpthese/; my @data = map { join( "", map { ( "a" .. "z" )[ rand 26 ] } 1 .. 10 + + rand( 10 ) ) . "" } 1 .. 1_000; cmpthese -10, { plus => sub { my @temp = @data; s/\s+$// for @temp; return @temp; }, star => sub { my @temp = @data; s/\s*$// for @temp; return @temp; } } ' Rate star plus star 334/s -- -72% plus 1211/s 263% --
It appears that \s+ is always faster than \s*. YMMV
|
|---|