Skip to content

Instantly share code, notes, and snippets.

@avar
Created May 28, 2010 19:04
Show Gist options
  • Select an option

  • Save avar/417579 to your computer and use it in GitHub Desktop.

Select an option

Save avar/417579 to your computer and use it in GitHub Desktop.
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