Created
October 20, 2010 09:55
-
-
Save onishi/636119 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
use Benchmark 'cmpthese'; | |
my $tagname = shift; | |
cmpthese( | |
1_000_000, | |
{ | |
regexp => sub { regexp($tagname) }, | |
lc_eq => sub { lc_eq($tagname) }, | |
regexp_subst => sub { regexp_subst($tagname) }, | |
lc_eq_subst => sub { lc_eq_subst($tagname) }, | |
} | |
); | |
sub regexp { | |
return ( $_[0] =~ /^(?:blockquote|q)$/i ); | |
} | |
sub regexp_subst { | |
my $tag = shift; | |
return ( $tag =~ /^(?:blockquote|q)$/i ); | |
} | |
sub lc_eq { | |
return ( lc($_[0]) eq 'blockquote' || lc($_[0]) eq 'q' ); | |
} | |
sub lc_eq_subst { | |
my $lt = lc($_[0]); | |
return ( $lt eq 'blockquote' || $lt eq 'q' ); | |
} | |
__END__ | |
# textarea | |
Rate regexp_subst regexp lc_eq_subst lc_eq | |
regexp_subst 1694915/s -- -22% -24% -32% | |
regexp 2173913/s 28% -- -2% -13% | |
lc_eq_subst 2222222/s 31% 2% -- -11% | |
lc_eq 2500000/s 47% 15% 12% -- | |
# blockquote | |
Rate regexp_subst regexp lc_eq_subst lc_eq | |
regexp_subst 1639344/s -- -21% -34% -48% | |
regexp 2083333/s 27% -- -17% -33% | |
lc_eq_subst 2500000/s 52% 20% -- -20% | |
lc_eq 3125000/s 91% 50% 25% -- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment