Created
June 3, 2012 11:49
-
-
Save rightgo09/2863181 to your computer and use it in GitHub Desktop.
Perl qr// op speed.
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
$ cat qr_speed.pl | |
use strict; | |
use Benchmark qw/ cmpthese /; | |
my $re_string = 'a.c'; | |
my $re_regexp = qr/a.c/; | |
sub match { | |
my $re = shift; | |
"abc" =~ /$re/; | |
} | |
cmpthese(1_000_000, { | |
string => sub { match($re_string) }, | |
regexp => sub { match($re_regexp) }, | |
}); | |
$ perlbrew exec perl qr_speed.pl | |
perl-5.10.1 | |
========== | |
Rate regexp string | |
regexp 1086957/s -- -45% | |
string 1960784/s 80% -- | |
perl-5.12.4 | |
========== | |
Rate regexp string | |
regexp 1176471/s -- -38% | |
string 1886792/s 60% -- | |
perl-5.14.2 | |
========== | |
Rate regexp string | |
regexp 1136364/s -- -51% | |
string 2325581/s 105% -- | |
perl-5.16.0 | |
========== | |
Rate regexp string | |
regexp 1063830/s -- -50% | |
string 2127660/s 100% -- | |
perl-5.17.0 | |
========== | |
Rate regexp string | |
regexp 1030928/s -- -44% | |
string 1851852/s 80% -- | |
perl-5.8.9 | |
========== | |
Rate regexp string | |
regexp 2173913/s -- -0% | |
string 2173913/s 0% -- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment