use strict; use Benchmark; my %snippet = ( a => 's/\s*#.*//', b => '$_ = $` if /#/', c => 'my ($line) = split/#/', d => '$_ = substr($_, 0, $-[0]) if /#/', e => 'if ((my $p = index($_, "#")) > -1) { substr($_, $p, -1, "") }' ); if (exists $snippet{$ARGV[0]}) { print "Processing $ARGV[0] snippet: '", $snippet{$ARGV[0]}, "'\n"; timethis (-10, $snippet{$ARGV[0]}); } else { print "Missing or invalid parameter to single1.p\n\n"; } #### rate c e a b d c 521648/s -- -4% -61% -68% -68% e 543110/s 4% -- -59% -66% -67% a 1335220/s 156% 146% -- -17% -19% b 1614068/s 209% 197% 21% -- -2% d 1639269/s 214% 202% 23% 2% -- #### use strict; use Benchmark qw(cmpthese); cmpthese (-10, { a => 's/\s*#.*//', b => '$_ = $` if /#/', c => 'my ($line) = split/#/', d => '$_ = substr($_, 0, $-[0]) if /#/', e => 'if ((my $p = index($_, "#")) > -1) { substr($_, $p, -1, "") }' }); #### Rate c e a d b c 518715/s -- -2% -62% -67% -68% e 530337/s 2% -- -61% -66% -67% a 1364925/s 163% 157% -- -14% -15% d 1582165/s 205% 198% 16% -- -1% b 1600284/s 209% 202% 17% 1% -- Rate c e a d b c 508712/s -- -5% -63% -68% -69% e 532810/s 5% -- -61% -66% -68% a 1365789/s 168% 156% -- -14% -17% d 1589576/s 212% 198% 16% -- -3% b 1639949/s 222% 208% 20% 3% -- Rate c e a d b c 509240/s -- -6% -63% -68% -68% e 544492/s 7% -- -60% -66% -66% a 1365411/s 168% 151% -- -15% -15% d 1599654/s 214% 194% 17% -- -1% b 1608742/s 216% 195% 18% 1% --