← Index
NYTProf Performance Profile   « line view »
For examples/benchmark4.pl
  Run on Thu Aug 28 19:01:43 2014
Reported on Thu Aug 28 19:02:42 2014

Filename/usr/lib/perl5/NetAddr/IP/Util.pm
StatementsExecuted 52 statements in 1.25ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
478201146.5ms46.5msNetAddr::IP::Util::::ipv4to6 NetAddr::IP::Util::ipv4to6 (xsub)
478201134.0ms34.0msNetAddr::IP::Util::::notcontiguous NetAddr::IP::Util::notcontiguous (xsub)
111155µs186µsNetAddr::IP::Util::::BEGIN@10 NetAddr::IP::Util::BEGIN@10
11142µs42µsNetAddr::IP::Util::::bootstrap NetAddr::IP::Util::bootstrap (xsub)
33323µs396µsNetAddr::IP::Util::::import NetAddr::IP::Util::import
11118µs618µsNetAddr::IP::UtilPolluted::::BEGIN@198NetAddr::IP::UtilPolluted::BEGIN@198
11111µs24µsNetAddr::IP::Util::::BEGIN@4 NetAddr::IP::Util::BEGIN@4
3118µs8µsNetAddr::IP::Util::::shiftleft NetAddr::IP::Util::shiftleft (xsub)
1118µs205µsNetAddr::IP::Util::::BEGIN@11 NetAddr::IP::Util::BEGIN@11
1118µs85µsNetAddr::IP::Util::::BEGIN@9 NetAddr::IP::Util::BEGIN@9
1117µs22µsNetAddr::IP::UtilPolluted::::BEGIN@197NetAddr::IP::UtilPolluted::BEGIN@197
1116µs60µsNetAddr::IP::Util::::BEGIN@8 NetAddr::IP::Util::BEGIN@8
1113µs3µsNetAddr::IP::Util::::CORE:match NetAddr::IP::Util::CORE:match (opcode)
1113µs3µsNetAddr::IP::Util::::mask4to6 NetAddr::IP::Util::mask4to6 (xsub)
0000s0sNetAddr::IP::Util::::DESTROY NetAddr::IP::Util::DESTROY
0000s0sNetAddr::IP::Util::::havegethostbyname2 NetAddr::IP::Util::havegethostbyname2
0000s0sNetAddr::IP::Util::::inet_4map6 NetAddr::IP::Util::inet_4map6
0000s0sNetAddr::IP::Util::::mode NetAddr::IP::Util::mode
0000s0sNetAddr::IP::Util::::naip_gethostbyname NetAddr::IP::Util::naip_gethostbyname
0000s0sNetAddr::IP::UtilPolluted::::__ANON__[:237]NetAddr::IP::UtilPolluted::__ANON__[:237]
0000s0sNetAddr::IP::UtilPolluted::::__ANON__[:245]NetAddr::IP::UtilPolluted::__ANON__[:245]
0000s0sNetAddr::IP::UtilPolluted::::__ANON__[:255]NetAddr::IP::UtilPolluted::__ANON__[:255]
0000s0sNetAddr::IP::UtilPolluted::::_end_gethostbynameNetAddr::IP::UtilPolluted::_end_gethostbyname
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1#!/usr/bin/perl
2package NetAddr::IP::Util;
3
4231µs236µs
# spent 24µs (11+12) within NetAddr::IP::Util::BEGIN@4 which was called: # once (11µs+12µs) by NetAddr::IP::Lite::BEGIN@18 at line 4
use strict;
# spent 24µs making 1 call to NetAddr::IP::Util::BEGIN@4 # spent 12µs making 1 call to strict::import
5#use diagnostics;
6#use lib qw(blib/lib);
7
8227µs2114µs
# spent 60µs (6+54) within NetAddr::IP::Util::BEGIN@8 which was called: # once (6µs+54µs) by NetAddr::IP::Lite::BEGIN@18 at line 8
use vars qw($VERSION @EXPORT_OK @ISA %EXPORT_TAGS $Mode);
# spent 60µs making 1 call to NetAddr::IP::Util::BEGIN@8 # spent 54µs making 1 call to vars::import
9226µs2162µs
# spent 85µs (8+77) within NetAddr::IP::Util::BEGIN@9 which was called: # once (8µs+77µs) by NetAddr::IP::Lite::BEGIN@18 at line 9
use AutoLoader qw(AUTOLOAD);
# spent 85µs making 1 call to NetAddr::IP::Util::BEGIN@9 # spent 77µs making 1 call to AutoLoader::import
102114µs1186µs
# spent 186µs (155+31) within NetAddr::IP::Util::BEGIN@10 which was called: # once (155µs+31µs) by NetAddr::IP::Lite::BEGIN@18 at line 10
use NetAddr::IP::Util_IS;
# spent 186µs making 1 call to NetAddr::IP::Util::BEGIN@10
1114µs1198µs
# spent 205µs (8+198) within NetAddr::IP::Util::BEGIN@11 which was called: # once (8µs+198µs) by NetAddr::IP::Lite::BEGIN@18 at line 14
use NetAddr::IP::InetBase qw(
# spent 198µs making 1 call to NetAddr::IP::InetBase::import
12 :upper
13 :all
141456µs1205µs);
# spent 205µs making 1 call to NetAddr::IP::Util::BEGIN@11
15
1612µs*NetAddr::IP::Util::upper = \&NetAddr::IP::InetBase::upper;
171400ns*NetAddr::IP::Util::lower = \&NetAddr::IP::InetBase::lower;
18
191400nsrequire DynaLoader;
201200nsrequire Exporter;
21
2219µs@ISA = qw(Exporter DynaLoader);
23
24314µs13µs$VERSION = do { my @r = (q$Revision: 1.50 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
# spent 3µs making 1 call to NetAddr::IP::Util::CORE:match
25
2614µs@EXPORT_OK = qw(
27 inet_aton
28 inet_ntoa
29 ipv6_aton
30 ipv6_ntoa
31 ipv6_n2x
32 ipv6_n2d
33 inet_any2n
34 hasbits
35 isIPv4
36 isNewIPv4
37 isAnyIPv4
38 inet_n2dx
39 inet_n2ad
40 inet_pton
41 inet_ntop
42 inet_4map6
43 shiftleft
44 addconst
45 add128
46 sub128
47 notcontiguous
48 bin2bcd
49 bcd2bin
50 mode
51 ipv4to6
52 mask4to6
53 ipanyto6
54 maskanyto6
55 ipv6to4
56 bin2bcdn
57 bcdn2txt
58 bcdn2bin
59 simple_pack
60 comp128
61 packzeros
62 AF_INET
63 AF_INET6
64 naip_gethostbyname
65 havegethostbyname2
66);
67
68110µs%EXPORT_TAGS = (
69 all => [@EXPORT_OK],
70 inet => [qw(
71 inet_aton
72 inet_ntoa
73 ipv6_aton
74 ipv6_ntoa
75 ipv6_n2x
76 ipv6_n2d
77 inet_any2n
78 inet_n2dx
79 inet_n2ad
80 inet_pton
81 inet_ntop
82 inet_4map6
83 ipv4to6
84 mask4to6
85 ipanyto6
86 maskanyto6
87 ipv6to4
88 packzeros
89 naip_gethostbyname
90 )],
91 math => [qw(
92 shiftleft
93 hasbits
94 isIPv4
95 isNewIPv4
96 isAnyIPv4
97 addconst
98 add128
99 sub128
100 notcontiguous
101 bin2bcd
102 bcd2bin
103 )],
104 ipv4 => [qw(
105 inet_aton
106 inet_ntoa
107 )],
108 ipv6 => [qw(
109 ipv6_aton
110 ipv6_ntoa
111 ipv6_n2x
112 ipv6_n2d
113 inet_any2n
114 inet_n2dx
115 inet_n2ad
116 inet_pton
117 inet_ntop
118 inet_4map6
119 ipv4to6
120 mask4to6
121 ipanyto6
122 maskanyto6
123 ipv6to4
124 packzeros
125 naip_gethostbyname
126 )],
127);
128
12913µs12µsif (NetAddr::IP::Util_IS->not_pure) {
# spent 2µs making 1 call to NetAddr::IP::Util_IS::not_pure
1301500ns eval { ## attempt to load 'C' version of utilities
13115µs1191µs bootstrap NetAddr::IP::Util $VERSION;
# spent 191µs making 1 call to DynaLoader::bootstrap
132 };
133}
13412µs11µsif (NetAddr::IP::Util_IS->pure || $@) { ## load the pure perl version if 'C' lib missing
# spent 1µs making 1 call to NetAddr::IP::Util_IS::pure
135 require NetAddr::IP::UtilPP;
136 import NetAddr::IP::UtilPP qw( :all );
137# require Socket;
138# import Socket qw(inet_ntoa);
139# *yinet_aton = \&Socket::inet_aton;
140 $Mode = 'Pure Perl';
141}
142else {
1431300ns $Mode = 'CC XS';
144}
145
146# if Socket lib is broken in some way, check for overange values
147#
148#my $overange = yinet_aton('256.1') ? 1:0;
149#my $overange = gethostbyname('256.1') ? 1:0;
150
151sub mode() { $Mode };
152
1531200ns12µsmy $_newV4compat = pack('N4',0,0,0xffff,0);
# spent 2µs making 1 call to main::CORE:pack
154
155sub inet_4map6 {
156 my $naddr = shift;
157 if (length($naddr) == 4) {
158 $naddr = ipv4to6($naddr);
159 }
160 elsif (length($naddr) == 16) {
161 ; # is OK
162 return undef unless isAnyIPv4($naddr);
163 } else {
164 return undef;
165 }
166 $naddr |= $_newV4compat;
167 return $naddr;
168}
169
170sub DESTROY {};
171
1721200nsmy $havegethostbyname2 = 0;
173
1741100nsmy $mygethostbyname;
175
1761100nsmy $_Sock6ok = 1; # for testing gethostbyname
177
178sub havegethostbyname2 {
179 return $_Sock6ok
180 ? $havegethostbyname2
181 : 0;
182}
183
184
# spent 396µs (23+374) within NetAddr::IP::Util::import which was called 3 times, avg 132µs/call: # once (11µs+201µs) by NetAddr::IP::Lite::BEGIN@18 at line 18 of NetAddr/IP/Lite.pm # once (6µs+123µs) by NetAddr::IP::BEGIN@9 at line 9 of NetAddr/IP.pm # once (5µs+50µs) by NetAddr::IP::FastNew::BEGIN@8 at line 8 of lib/NetAddr/IP/FastNew.pm
sub import {
18535µs if (grep { $_ eq ':noSock6' } @_) {
186 $_Sock6ok = 0;
187 @_ = grep { $_ ne ':noSock6' } @_;
188 }
189313µs343µs NetAddr::IP::Util->export_to_level(1,@_);
# spent 43µs making 3 calls to Exporter::export_to_level, avg 14µs/call
190}
191
192package NetAddr::IP::UtilPolluted;
193
194# Socket pollutes the name space with all of its symbols. Since
195# we don't want them all, confine them to this name space.
196
197225µs238µs
# spent 22µs (7+15) within NetAddr::IP::UtilPolluted::BEGIN@197 which was called: # once (7µs+15µs) by NetAddr::IP::Lite::BEGIN@18 at line 197
use strict;
# spent 22µs making 1 call to NetAddr::IP::UtilPolluted::BEGIN@197 # spent 15µs making 1 call to strict::import
1982405µs21.22ms
# spent 618µs (18+600) within NetAddr::IP::UtilPolluted::BEGIN@198 which was called: # once (18µs+600µs) by NetAddr::IP::Lite::BEGIN@18 at line 198
use Socket;
# spent 618µs making 1 call to NetAddr::IP::UtilPolluted::BEGIN@198 # spent 600µs making 1 call to Exporter::import
199
2001200ns11µsmy $_v4zero = pack('L',0);
# spent 1µs making 1 call to main::CORE:pack
2011100ns1800nsmy $_zero = pack('L4',0,0,0,0);
# spent 800ns making 1 call to main::CORE:pack
202
203# invoke replacement subroutine for Perl's "gethostbyname"
204# if Socket6 is available.
205#
206# NOTE: in certain BSD implementations, Perl's gethostbyname is broken
207# we will use our own InetBase::inet_aton instead
208
209sub _end_gethostbyname {
210# my ($name,$aliases,$addrtype,$length,@addrs) = @_;
211 my @rv = @_;
212# first ip address = rv[4]
213 my $tip = $rv[4];
214 unless ($tip && $tip ne $_v4zero && $tip ne $_zero) {
215 @rv = ();
216 }
217# length = rv[3]
218 elsif ($rv[3] && $rv[3] == 4) {
219 foreach (4..$#rv) {
220 $rv[$_] = NetAddr::IP::Util::inet_4map6(NetAddr::IP::Util::ipv4to6($rv[$_]));
221 }
222 $rv[3] = 16; # unconditionally set length to 16
223 }
224 elsif ($rv[3] == 16) {
225 ; # is ok
226 } else {
227 @rv = ();
228 }
229 return @rv;
230}
231
23222µsunless ( eval { require Socket6 }) {
233 $mygethostbyname = sub {
234# SEE NOTE above about broken BSD
235 my @tip = gethostbyname(NetAddr::IP::InetBase::fillIPv4($_[0]));
236 return &_end_gethostbyname(@tip);
237 };
238} else {
23912µs125µs import Socket6 qw( gethostbyname2 getipnodebyname );
# spent 25µs making 1 call to Exporter::import
240360µs151µs my $try = eval { my @try = gethostbyname2('127.0.0.1',NetAddr::IP::Util::AF_INET()); $try[4] };
# spent 51µs making 1 call to Socket6::gethostbyname2
2411900ns if (! $@ && $try && $try eq INADDR_LOOPBACK()) {
24211µs *_ghbn2 = \&Socket6::gethostbyname2;
2431300ns $havegethostbyname2 = 1;
244 } else {
245 *_ghbn2 = sub { return () }; # use failure branch below
246 }
247
248 $mygethostbyname = sub {
249 my @tip;
250 unless ($_Sock6ok && (@tip = _ghbn2($_[0],NetAddr::IP::Util::AF_INET6())) && @tip > 1) {
251# SEE NOTE above about broken BSD
252 @tip = gethostbyname(NetAddr::IP::InetBase::fillIPv4($_[0]));
253 }
254 return &_end_gethostbyname(@tip);
25513µs };
256}
257
258package NetAddr::IP::Util;
259
260sub naip_gethostbyname {
261# turn off complaint from Socket6 about missing numeric argument
262 undef local $^W;
263 my @rv = &$mygethostbyname($_[0]);
264 return wantarray
265 ? @rv
266 : $rv[4];
267}
268
269122µs1;
270
271__END__
 
# spent 3µs within NetAddr::IP::Util::CORE:match which was called: # once (3µs+0s) by NetAddr::IP::Lite::BEGIN@18 at line 24
sub NetAddr::IP::Util::CORE:match; # opcode
# spent 42µs within NetAddr::IP::Util::bootstrap which was called: # once (42µs+0s) by DynaLoader::bootstrap at line 207 of DynaLoader.pm
sub NetAddr::IP::Util::bootstrap; # xsub
# spent 46.5ms within NetAddr::IP::Util::ipv4to6 which was called 47820 times, avg 973ns/call: # 47820 times (46.5ms+0s) by NetAddr::IP::Lite::_xnew at line 1043 of NetAddr/IP/Lite.pm, avg 973ns/call
sub NetAddr::IP::Util::ipv4to6; # xsub
# spent 3µs within NetAddr::IP::Util::mask4to6 which was called: # once (3µs+0s) by NetAddr::IP::BEGIN@8 at line 652 of NetAddr/IP/Lite.pm
sub NetAddr::IP::Util::mask4to6; # xsub
# spent 34.0ms within NetAddr::IP::Util::notcontiguous which was called 47820 times, avg 711ns/call: # 47820 times (34.0ms+0s) by NetAddr::IP::Lite::_xnew at line 1059 of NetAddr/IP/Lite.pm, avg 711ns/call
sub NetAddr::IP::Util::notcontiguous; # xsub
# spent 8µs within NetAddr::IP::Util::shiftleft which was called 3 times, avg 3µs/call: # 3 times (8µs+0s) by NetAddr::IP::Lite::_xnew at line 893 of NetAddr/IP/Lite.pm, avg 3µs/call
sub NetAddr::IP::Util::shiftleft; # xsub