Skip to content

Instantly share code, notes, and snippets.

@hirose31
Forked from kazeburo/gist:246186
Created December 2, 2009 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hirose31/247251 to your computer and use it in GitHub Desktop.
Save hirose31/247251 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use Benchmark;
use Net::CIDR::Lite;
use Net::IP::Match::XS;
use Net::IP::Match::Bin;
use Net::IP::Match::Regexp;
use Net::Patricia;
our @willcom_ip_public = (
"125.28.1.0/24",
"61.204.0.0/24",
"210.168.246.0/24",
"210.168.247.0/24",
"219.108.7.0/24",
"61.204.2.0/24",
"61.204.5.0/24",
"61.198.129.0/24",
"61.198.140.0/24",
"61.198.141.0/24",
"125.28.15.0/24",
"61.198.165.0/24",
"61.198.166.0/24",
"61.198.168.0/24",
"61.198.169.0/24",
"61.198.170.0/24",
"61.198.248.0/24",
"61.198.138.100/32",
"61.198.138.101/32",
"61.198.138.102/32",
"61.198.139.160/28",
"61.198.139.128/27",
"61.198.138.103/32",
"61.198.139.0/29",
"61.198.252.0/24",
"61.204.3.128/25",
"211.126.192.128/25",
);
my $count = 300000;
my $cidr = Net::CIDR::Lite->new;
$cidr->add_any($_) for @willcom_ip_public;
my $bin = Net::IP::Match::Bin->new();
$bin->add($_) for @willcom_ip_public;
my @cidr_list = $cidr->list;
my $re = Net::IP::Match::Regexp::create_iprange_regexp(@willcom_ip_public);
my $pat = Net::Patricia->new;
$pat->add_string($_) for @willcom_ip_public;
timethese( $count , {
'regexp' => sub {
Net::IP::Match::Regexp::match_ip('210.169.99.3',$re);
},
'cidr' => sub {
$cidr->find('210.169.99.3');
},
'xs' => sub {
Net::IP::Match::XS::match_ip('210.169.99.3',@willcom_ip_public);
},
'bin' => sub {
$bin->match_ip('210.169.99.3');
},
'patricia' => sub {
$pat->match_string('210.169.99.3');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment