Skip to content

Instantly share code, notes, and snippets.

@ysasaki
Created October 23, 2010 14:45
Show Gist options
  • Save ysasaki/642291 to your computer and use it in GitHub Desktop.
Save ysasaki/642291 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
# benchmark for
# http://gist.github.com/641766
use strict;
use warnings;
use Benchmark qw(cmpthese);
my $xxx = "a";
my $str = "aaabbbaaabbb";
cmpthese( 100_000, {
'tr+eval'=> sub {
eval "\$str =~ tr/$xxx//";
},
's' => sub {
$str =~ s/($xxx)/$1/g;
},
});
__END__
ysasaki@ysasaki-x60:/tmp$ perl -v | grep version
This is perl 5, version 12, subversion 2 (v5.12.2) built for i686-linux
ysasaki@ysasaki-x60:/tmp$ uname -a
Linux ysasaki-x60 2.6.32-21-generic-pae #32-Ubuntu SMP Fri Apr 16 09:39:35 UTC 2010 i686 GNU/Linux
Rate tr+eval s
tr+eval 39062/s -- -67%
s 119048/s 205% --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment