Created
September 27, 2010 16:46
-
-
Save comewalk/599343 to your computer and use it in GitHub Desktop.
compared NetAddr::IP with Net::IP
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
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Net::IP; | |
use NetAddr::IP; | |
use Benchmark ':all'; | |
cmpthese(timethese(1000, { | |
'Net::IP' => sub { my $ip = Net::IP->new('192.168.0.1'); $ip->short(); }, | |
'NetAddr::IP' => sub { my $ip = NetAddr::IP->new('192.168.0.1'); $ip->short(); }, | |
})); | |
print "\n"; | |
cmpthese(timethese(1000, { | |
'Net::IP' => sub { my $ip = Net::IP->new('fd00::1'); $ip->short(); }, | |
'NetAddr::IP' => sub { my $ip = NetAddr::IP->new('fd00::1'); $ip->short(); }, | |
})); | |
print "\n"; | |
cmpthese(timethese(1000, { | |
'Net::IP' => sub { my $ip = Net::IP->new('192.168.0.0/24'); $ip->overlaps(Net::IP->new('192.168.0.1'))}, | |
'NetAddr::IP' => sub { my $ip = NetAddr::IP->new('192.168.0.0/24'); $ip->contains(NetAddr::IP->new('192.168.0.1')) }, | |
})); | |
print "\n"; | |
cmpthese(timethese(1000, { | |
'Net::IP' => sub { my $ip = Net::IP->new('192.168.0.0/24'); $ip->overlaps(Net::IP->new('192.168.0.1'))}, | |
'NetAddr::IP' => sub { my $ip = NetAddr::IP->new('192.168.0.0/24'); $ip->contains(NetAddr::IP->new('192.168.0.1')) }, | |
})); | |
print "\n"; | |
cmpthese(timethese(1000, { | |
'Net::IP' => sub { my $ip = Net::IP->new('fd00::/24'); $ip->overlaps(Net::IP->new('fd00::1'))}, | |
'NetAddr::IP' => sub { my $ip = NetAddr::IP->new('fd00::/24'); $ip->contains(NetAddr::IP->new('fd00::1')) }, | |
})); | |
__END__ | |
$ perl ipv6_benchmark.pl | |
Benchmark: timing 1000 iterations of Net::IP, NetAddr::IP... | |
Net::IP: 0 wallclock secs ( 0.76 usr + 0.00 sys = 0.76 CPU) @ 1315.79/s (n=1000) | |
NetAddr::IP: 1 wallclock secs ( 0.16 usr + 0.00 sys = 0.16 CPU) @ 6250.00/s (n=1000) | |
(warning: too few iterations for a reliable count) | |
Rate Net::IP NetAddr::IP | |
Net::IP 1316/s -- -79% | |
NetAddr::IP 6250/s 375% -- | |
Benchmark: timing 1000 iterations of Net::IP, NetAddr::IP... | |
Net::IP: 1 wallclock secs ( 1.38 usr + 0.00 sys = 1.38 CPU) @ 724.64/s (n=1000) | |
NetAddr::IP: 0 wallclock secs ( 0.24 usr + 0.00 sys = 0.24 CPU) @ 4166.67/s (n=1000) | |
(warning: too few iterations for a reliable count) | |
Rate Net::IP NetAddr::IP | |
Net::IP 725/s -- -83% | |
NetAddr::IP 4167/s 475% -- | |
Benchmark: timing 1000 iterations of Net::IP, NetAddr::IP... | |
Net::IP: 3 wallclock secs ( 2.96 usr + 0.00 sys = 2.96 CPU) @ 337.84/s (n=1000) | |
NetAddr::IP: 1 wallclock secs ( 0.20 usr + 0.01 sys = 0.21 CPU) @ 4761.90/s (n=1000) | |
(warning: too few iterations for a reliable count) | |
Rate Net::IP NetAddr::IP | |
Net::IP 338/s -- -93% | |
NetAddr::IP 4762/s 1310% -- | |
Benchmark: timing 1000 iterations of Net::IP, NetAddr::IP... | |
Net::IP: 5 wallclock secs ( 5.08 usr + 0.00 sys = 5.08 CPU) @ 196.85/s (n=1000) | |
NetAddr::IP: 0 wallclock secs ( 0.40 usr + 0.00 sys = 0.40 CPU) @ 2500.00/s (n=1000) | |
Rate Net::IP NetAddr::IP | |
Net::IP 197/s -- -92% | |
NetAddr::IP 2500/s 1170% -- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment