Created
May 28, 2010 19:04
-
-
Save avar/417579 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 5.010; | |
| use strict; | |
| use warnings; | |
| use autodie; | |
| use Benchmark qw/ :all /; | |
| use File::Slurp qw/ slurp /; | |
| use Regexp::Common qw/URI/; | |
| my $file = $ARGV[0]; | |
| my @file = split /\n/, slurp $file; | |
| my %name; | |
| my $test = sub { | |
| my $name = shift; | |
| my $sub = shift; | |
| my $count = 0; | |
| for (@file) { | |
| $count++ if $sub->(); | |
| } | |
| warn "$name had $count hits" unless $name{$name}++; | |
| }; | |
| cmpthese(25, { | |
| re_URI => sub { | |
| $test->( "re_URI", sub { /^($RE{URI}{HTTP})/o } ); | |
| }, | |
| re_URI_index => sub { | |
| $test->( "re_URI_index", sub { index($_, "://") != -1 and $_ =~ /^($RE{URI})/o } ); | |
| }, | |
| re_URI_HTTP_index => sub { | |
| $test->( "re_URI_HTTP_index", sub { index($_, "://") != -1 and $_ =~ /^($RE{URI}{HTTP})/o or $_ =~ /^($RE{URI})/o } ); | |
| }, | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment