Skip to content

Instantly share code, notes, and snippets.

@rightgo09
Created March 14, 2012 11:30
Show Gist options
  • Save rightgo09/2035892 to your computer and use it in GitHub Desktop.
Save rightgo09/2035892 to your computer and use it in GitHub Desktop.
use Benchmark qw(cmpthese timethese);
cmpthese(timethese(1_000_000, {
's///' => sub {
my $str = q!1qaz2wsx(3edc4rfv5tgb)6yhn7ujm!;
my $del = q!4rfv5tgb)6yhn!;
$del =~ s/([\(\)])/\\$1/g;
$str =~ s/$del//;
},
'quotemeta' => sub {
my $str = q!1qaz2wsx(3edc4rfv5tgb)6yhn7ujm!;
my $del = q!4rfv5tgb)6yhn!;
$del = quotemeta($del);
$str =~ s/$del//;
},
'\Q' => sub {
my $str = q!1qaz2wsx(3edc4rfv5tgb)6yhn7ujm!;
my $del = q!4rfv5tgb)6yhn!;
$str =~ s/\Q$del\E//;
},
'substr' => sub {
my $str = q!1qaz2wsx(3edc4rfv5tgb)6yhn7ujm!;
my $del = q!4rfv5tgb)6yhn!;
substr($str, index($str, $del), length($del)) = "";
},
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment