← Index
NYTProf Performance Profile   « line view »
For /usr/local/bin/sa-learn
  Run on Tue Nov 7 05:38:10 2017
Reported on Tue Nov 7 06:16:04 2017

Filename/usr/local/lib/perl5/site_perl/URI/_punycode.pm
StatementsExecuted 29 statements in 2.75ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11143µs230µsURI::_punycode::::BEGIN@21URI::_punycode::BEGIN@21
11141µs54µsURI::_punycode::::BEGIN@3URI::_punycode::BEGIN@3
11135µs63µsURI::_punycode::::BEGIN@4URI::_punycode::BEGIN@4
11131µs225µsURI::_punycode::::BEGIN@18URI::_punycode::BEGIN@18
11130µs224µsURI::_punycode::::BEGIN@22URI::_punycode::BEGIN@22
11129µs198µsURI::_punycode::::BEGIN@19URI::_punycode::BEGIN@19
11128µs194µsURI::_punycode::::BEGIN@20URI::_punycode::BEGIN@20
11125µs217µsURI::_punycode::::BEGIN@16URI::_punycode::BEGIN@16
11124µs31µsURI::_punycode::::BEGIN@12URI::_punycode::BEGIN@12
11118µs64µsURI::_punycode::::BEGIN@9URI::_punycode::BEGIN@9
11117µs199µsURI::_punycode::::BEGIN@17URI::_punycode::BEGIN@17
11117µs17µsURI::_punycode::::CORE:qrURI::_punycode::CORE:qr (opcode)
0000s0sURI::_punycode::::_croakURI::_punycode::_croak
0000s0sURI::_punycode::::adaptURI::_punycode::adapt
0000s0sURI::_punycode::::code_pointURI::_punycode::code_point
0000s0sURI::_punycode::::decode_punycodeURI::_punycode::decode_punycode
0000s0sURI::_punycode::::digit_valueURI::_punycode::digit_value
0000s0sURI::_punycode::::encode_punycodeURI::_punycode::encode_punycode
0000s0sURI::_punycode::::minURI::_punycode::min
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package URI::_punycode;
2
3257µs268µs
# spent 54µs (41+13) within URI::_punycode::BEGIN@3 which was called: # once (41µs+13µs) by URI::_idna::BEGIN@9 at line 3
use strict;
# spent 54µs making 1 call to URI::_punycode::BEGIN@3 # spent 13µs making 1 call to strict::import
42116µs291µs
# spent 63µs (35+28) within URI::_punycode::BEGIN@4 which was called: # once (35µs+28µs) by URI::_idna::BEGIN@9 at line 4
use warnings;
# spent 63µs making 1 call to URI::_punycode::BEGIN@4 # spent 28µs making 1 call to warnings::import
5
612µsour $VERSION = '1.72';
7135µs$VERSION = eval $VERSION;
# spent 6µs executing statements in string eval
8
9289µs2110µs
# spent 64µs (18+46) within URI::_punycode::BEGIN@9 which was called: # once (18µs+46µs) by URI::_idna::BEGIN@9 at line 9
use Exporter 'import';
# spent 64µs making 1 call to URI::_punycode::BEGIN@9 # spent 46µs making 1 call to Exporter::import
1017µsour @EXPORT = qw(encode_punycode decode_punycode);
11
12294µs238µs
# spent 31µs (24+7) within URI::_punycode::BEGIN@12 which was called: # once (24µs+7µs) by URI::_idna::BEGIN@9 at line 12
use integer;
# spent 31µs making 1 call to URI::_punycode::BEGIN@12 # spent 7µs making 1 call to integer::import
13
1412µsour $DEBUG = 0;
15
16268µs2410µs
# spent 217µs (25+193) within URI::_punycode::BEGIN@16 which was called: # once (25µs+193µs) by URI::_idna::BEGIN@9 at line 16
use constant BASE => 36;
# spent 217µs making 1 call to URI::_punycode::BEGIN@16 # spent 193µs making 1 call to constant::import
17275µs2380µs
# spent 199µs (17+182) within URI::_punycode::BEGIN@17 which was called: # once (17µs+182µs) by URI::_idna::BEGIN@9 at line 17
use constant TMIN => 1;
# spent 199µs making 1 call to URI::_punycode::BEGIN@17 # spent 182µs making 1 call to constant::import
18271µs2419µs
# spent 225µs (31+194) within URI::_punycode::BEGIN@18 which was called: # once (31µs+194µs) by URI::_idna::BEGIN@9 at line 18
use constant TMAX => 26;
# spent 225µs making 1 call to URI::_punycode::BEGIN@18 # spent 194µs making 1 call to constant::import
19252µs2366µs
# spent 198µs (29+169) within URI::_punycode::BEGIN@19 which was called: # once (29µs+169µs) by URI::_idna::BEGIN@9 at line 19
use constant SKEW => 38;
# spent 198µs making 1 call to URI::_punycode::BEGIN@19 # spent 169µs making 1 call to constant::import
20259µs2360µs
# spent 194µs (28+166) within URI::_punycode::BEGIN@20 which was called: # once (28µs+166µs) by URI::_idna::BEGIN@9 at line 20
use constant DAMP => 700;
# spent 194µs making 1 call to URI::_punycode::BEGIN@20 # spent 166µs making 1 call to constant::import
21287µs2418µs
# spent 230µs (43+188) within URI::_punycode::BEGIN@21 which was called: # once (43µs+188µs) by URI::_idna::BEGIN@9 at line 21
use constant INITIAL_BIAS => 72;
# spent 230µs making 1 call to URI::_punycode::BEGIN@21 # spent 188µs making 1 call to constant::import
2221.89ms2418µs
# spent 224µs (30+194) within URI::_punycode::BEGIN@22 which was called: # once (30µs+194µs) by URI::_idna::BEGIN@9 at line 22
use constant INITIAL_N => 128;
# spent 224µs making 1 call to URI::_punycode::BEGIN@22 # spent 194µs making 1 call to constant::import
23
2412µsmy $Delimiter = chr 0x2D;
25132µs117µsmy $BasicRE = qr/[\x00-\x7f]/;
# spent 17µs making 1 call to URI::_punycode::CORE:qr
26
27sub _croak { require Carp; Carp::croak(@_); }
28
29sub digit_value {
30 my $code = shift;
31 return ord($code) - ord("A") if $code =~ /[A-Z]/;
32 return ord($code) - ord("a") if $code =~ /[a-z]/;
33 return ord($code) - ord("0") + 26 if $code =~ /[0-9]/;
34 return;
35}
36
37sub code_point {
38 my $digit = shift;
39 return $digit + ord('a') if 0 <= $digit && $digit <= 25;
40 return $digit + ord('0') - 26 if 26 <= $digit && $digit <= 36;
41 die 'NOT COME HERE';
42}
43
44sub adapt {
45 my($delta, $numpoints, $firsttime) = @_;
46 $delta = $firsttime ? $delta / DAMP : $delta / 2;
47 $delta += $delta / $numpoints;
48 my $k = 0;
49 while ($delta > ((BASE - TMIN) * TMAX) / 2) {
50 $delta /= BASE - TMIN;
51 $k += BASE;
52 }
53 return $k + (((BASE - TMIN + 1) * $delta) / ($delta + SKEW));
54}
55
56sub decode_punycode {
57 my $code = shift;
58
59 my $n = INITIAL_N;
60 my $i = 0;
61 my $bias = INITIAL_BIAS;
62 my @output;
63
64 if ($code =~ s/(.*)$Delimiter//o) {
65 push @output, map ord, split //, $1;
66 return _croak('non-basic code point') unless $1 =~ /^$BasicRE*$/o;
67 }
68
69 while ($code) {
70 my $oldi = $i;
71 my $w = 1;
72 LOOP:
73 for (my $k = BASE; 1; $k += BASE) {
74 my $cp = substr($code, 0, 1, '');
75 my $digit = digit_value($cp);
76 defined $digit or return _croak("invalid punycode input");
77 $i += $digit * $w;
78 my $t = ($k <= $bias) ? TMIN
79 : ($k >= $bias + TMAX) ? TMAX : $k - $bias;
80 last LOOP if $digit < $t;
81 $w *= (BASE - $t);
82 }
83 $bias = adapt($i - $oldi, @output + 1, $oldi == 0);
84 warn "bias becomes $bias" if $DEBUG;
85 $n += $i / (@output + 1);
86 $i = $i % (@output + 1);
87 splice(@output, $i, 0, $n);
88 warn join " ", map sprintf('%04x', $_), @output if $DEBUG;
89 $i++;
90 }
91 return join '', map chr, @output;
92}
93
94sub encode_punycode {
95 my $input = shift;
96 my @input = split //, $input;
97
98 my $n = INITIAL_N;
99 my $delta = 0;
100 my $bias = INITIAL_BIAS;
101
102 my @output;
103 my @basic = grep /$BasicRE/, @input;
104 my $h = my $b = @basic;
105 push @output, @basic;
106 push @output, $Delimiter if $b && $h < @input;
107 warn "basic codepoints: (@output)" if $DEBUG;
108
109 while ($h < @input) {
110 my $m = min(grep { $_ >= $n } map ord, @input);
111 warn sprintf "next code point to insert is %04x", $m if $DEBUG;
112 $delta += ($m - $n) * ($h + 1);
113 $n = $m;
114 for my $i (@input) {
115 my $c = ord($i);
116 $delta++ if $c < $n;
117 if ($c == $n) {
118 my $q = $delta;
119 LOOP:
120 for (my $k = BASE; 1; $k += BASE) {
121 my $t = ($k <= $bias) ? TMIN :
122 ($k >= $bias + TMAX) ? TMAX : $k - $bias;
123 last LOOP if $q < $t;
124 my $cp = code_point($t + (($q - $t) % (BASE - $t)));
125 push @output, chr($cp);
126 $q = ($q - $t) / (BASE - $t);
127 }
128 push @output, chr(code_point($q));
129 $bias = adapt($delta, $h + 1, $h == $b);
130 warn "bias becomes $bias" if $DEBUG;
131 $delta = 0;
132 $h++;
133 }
134 }
135 $delta++;
136 $n++;
137 }
138 return join '', @output;
139}
140
141sub min {
142 my $min = shift;
143 for (@_) { $min = $_ if $_ <= $min }
144 return $min;
145}
146
147112µs1;
148__END__
 
# spent 17µs within URI::_punycode::CORE:qr which was called: # once (17µs+0s) by URI::_idna::BEGIN@9 at line 25
sub URI::_punycode::CORE:qr; # opcode