Skip to content

Instantly share code, notes, and snippets.

Created October 10, 2010 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/619356 to your computer and use it in GitHub Desktop.
Save anonymous/619356 to your computer and use it in GitHub Desktop.
use v6;
use Benchmark;
my $string = "a b c d \n";
my %results = timethese(1000, {
"chomp" => sub { $string.chomp },
"chop" => sub { $string.chop if $string.substr(-1) == any("\n", "\r\n") },
"flip" => sub { $string.flip.substr(1).flip if $string.substr(-1) == any("\n", "\r\n") },
"substr" => sub { $string.substr(0,-1) if $string.substr(-1) == any("\n", "\r\n") },
});
say ~%results;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment