Created
October 23, 2010 14:45
-
-
Save ysasaki/642291 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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