← Index
NYTProf Performance Profile   « line view »
For flows_to_es.pl
  Run on Mon May 9 23:27:59 2016
Reported on Mon May 9 23:28:09 2016

Filename/usr/share/perl5/URI/_punycode.pm
StatementsExecuted 26 statements in 1.55ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111154µs157µsURI::_punycode::::BEGIN@10URI::_punycode::BEGIN@10
11112µs25µsURI::_punycode::::BEGIN@3URI::_punycode::BEGIN@3
1119µs45µsURI::_punycode::::BEGIN@20URI::_punycode::BEGIN@20
1119µs46µsURI::_punycode::::BEGIN@14URI::_punycode::BEGIN@14
1118µs37µsURI::_punycode::::BEGIN@15URI::_punycode::BEGIN@15
1118µs35µsURI::_punycode::::BEGIN@16URI::_punycode::BEGIN@16
1118µs34µsURI::_punycode::::BEGIN@17URI::_punycode::BEGIN@17
1118µs34µsURI::_punycode::::BEGIN@18URI::_punycode::BEGIN@18
1117µs33µsURI::_punycode::::BEGIN@19URI::_punycode::BEGIN@19
1112µs2µ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
3266µs239µs
# spent 25µs (12+14) within URI::_punycode::BEGIN@3 which was called: # once (12µs+14µs) by URI::_idna::BEGIN@7 at line 3
use strict;
# spent 25µs making 1 call to URI::_punycode::BEGIN@3 # spent 14µs making 1 call to strict::import
41700nsour $VERSION = "0.04";
5
61500nsrequire Exporter;
716µsour @ISA = qw(Exporter);
81700nsour @EXPORT = qw(encode_punycode decode_punycode);
9
102186µs2159µs
# spent 157µs (154+3) within URI::_punycode::BEGIN@10 which was called: # once (154µs+3µs) by URI::_idna::BEGIN@7 at line 10
use integer;
# spent 157µs making 1 call to URI::_punycode::BEGIN@10 # spent 3µs making 1 call to integer::import
11
121200nsour $DEBUG = 0;
13
14233µs282µs
# spent 46µs (9+37) within URI::_punycode::BEGIN@14 which was called: # once (9µs+37µs) by URI::_idna::BEGIN@7 at line 14
use constant BASE => 36;
# spent 46µs making 1 call to URI::_punycode::BEGIN@14 # spent 37µs making 1 call to constant::import
15231µs266µs
# spent 37µs (8+29) within URI::_punycode::BEGIN@15 which was called: # once (8µs+29µs) by URI::_idna::BEGIN@7 at line 15
use constant TMIN => 1;
# spent 37µs making 1 call to URI::_punycode::BEGIN@15 # spent 29µs making 1 call to constant::import
16230µs262µs
# spent 35µs (8+27) within URI::_punycode::BEGIN@16 which was called: # once (8µs+27µs) by URI::_idna::BEGIN@7 at line 16
use constant TMAX => 26;
# spent 35µs making 1 call to URI::_punycode::BEGIN@16 # spent 27µs making 1 call to constant::import
17231µs260µs
# spent 34µs (8+26) within URI::_punycode::BEGIN@17 which was called: # once (8µs+26µs) by URI::_idna::BEGIN@7 at line 17
use constant SKEW => 38;
# spent 34µs making 1 call to URI::_punycode::BEGIN@17 # spent 26µs making 1 call to constant::import
18230µs260µs
# spent 34µs (8+26) within URI::_punycode::BEGIN@18 which was called: # once (8µs+26µs) by URI::_idna::BEGIN@7 at line 18
use constant DAMP => 700;
# spent 34µs making 1 call to URI::_punycode::BEGIN@18 # spent 26µs making 1 call to constant::import
19230µs259µs
# spent 33µs (7+26) within URI::_punycode::BEGIN@19 which was called: # once (7µs+26µs) by URI::_idna::BEGIN@7 at line 19
use constant INITIAL_BIAS => 72;
# spent 33µs making 1 call to URI::_punycode::BEGIN@19 # spent 26µs making 1 call to constant::import
2021.09ms280µs
# spent 45µs (9+36) within URI::_punycode::BEGIN@20 which was called: # once (9µs+36µs) by URI::_idna::BEGIN@7 at line 20
use constant INITIAL_N => 128;
# spent 45µs making 1 call to URI::_punycode::BEGIN@20 # spent 36µs making 1 call to constant::import
21
221300nsmy $Delimiter = chr 0x2D;
2319µs12µsmy $BasicRE = qr/[\x00-\x7f]/;
# spent 2µs making 1 call to URI::_punycode::CORE:qr
24
25sub _croak { require Carp; Carp::croak(@_); }
26
27sub digit_value {
28 my $code = shift;
29 return ord($code) - ord("A") if $code =~ /[A-Z]/;
30 return ord($code) - ord("a") if $code =~ /[a-z]/;
31 return ord($code) - ord("0") + 26 if $code =~ /[0-9]/;
32 return;
33}
34
35sub code_point {
36 my $digit = shift;
37 return $digit + ord('a') if 0 <= $digit && $digit <= 25;
38 return $digit + ord('0') - 26 if 26 <= $digit && $digit <= 36;
39 die 'NOT COME HERE';
40}
41
42sub adapt {
43 my($delta, $numpoints, $firsttime) = @_;
44 $delta = $firsttime ? $delta / DAMP : $delta / 2;
45 $delta += $delta / $numpoints;
46 my $k = 0;
47 while ($delta > ((BASE - TMIN) * TMAX) / 2) {
48 $delta /= BASE - TMIN;
49 $k += BASE;
50 }
51 return $k + (((BASE - TMIN + 1) * $delta) / ($delta + SKEW));
52}
53
54sub decode_punycode {
55 my $code = shift;
56
57 my $n = INITIAL_N;
58 my $i = 0;
59 my $bias = INITIAL_BIAS;
60 my @output;
61
62 if ($code =~ s/(.*)$Delimiter//o) {
63 push @output, map ord, split //, $1;
64 return _croak('non-basic code point') unless $1 =~ /^$BasicRE*$/o;
65 }
66
67 while ($code) {
68 my $oldi = $i;
69 my $w = 1;
70 LOOP:
71 for (my $k = BASE; 1; $k += BASE) {
72 my $cp = substr($code, 0, 1, '');
73 my $digit = digit_value($cp);
74 defined $digit or return _croak("invalid punycode input");
75 $i += $digit * $w;
76 my $t = ($k <= $bias) ? TMIN
77 : ($k >= $bias + TMAX) ? TMAX : $k - $bias;
78 last LOOP if $digit < $t;
79 $w *= (BASE - $t);
80 }
81 $bias = adapt($i - $oldi, @output + 1, $oldi == 0);
82 warn "bias becomes $bias" if $DEBUG;
83 $n += $i / (@output + 1);
84 $i = $i % (@output + 1);
85 splice(@output, $i, 0, $n);
86 warn join " ", map sprintf('%04x', $_), @output if $DEBUG;
87 $i++;
88 }
89 return join '', map chr, @output;
90}
91
92sub encode_punycode {
93 my $input = shift;
94 my @input = split //, $input;
95
96 my $n = INITIAL_N;
97 my $delta = 0;
98 my $bias = INITIAL_BIAS;
99
100 my @output;
101 my @basic = grep /$BasicRE/, @input;
102 my $h = my $b = @basic;
103 push @output, @basic;
104 push @output, $Delimiter if $b && $h < @input;
105 warn "basic codepoints: (@output)" if $DEBUG;
106
107 while ($h < @input) {
108 my $m = min(grep { $_ >= $n } map ord, @input);
109 warn sprintf "next code point to insert is %04x", $m if $DEBUG;
110 $delta += ($m - $n) * ($h + 1);
111 $n = $m;
112 for my $i (@input) {
113 my $c = ord($i);
114 $delta++ if $c < $n;
115 if ($c == $n) {
116 my $q = $delta;
117 LOOP:
118 for (my $k = BASE; 1; $k += BASE) {
119 my $t = ($k <= $bias) ? TMIN :
120 ($k >= $bias + TMAX) ? TMAX : $k - $bias;
121 last LOOP if $q < $t;
122 my $cp = code_point($t + (($q - $t) % (BASE - $t)));
123 push @output, chr($cp);
124 $q = ($q - $t) / (BASE - $t);
125 }
126 push @output, chr(code_point($q));
127 $bias = adapt($delta, $h + 1, $h == $b);
128 warn "bias becomes $bias" if $DEBUG;
129 $delta = 0;
130 $h++;
131 }
132 }
133 $delta++;
134 $n++;
135 }
136 return join '', @output;
137}
138
139sub min {
140 my $min = shift;
141 for (@_) { $min = $_ if $_ <= $min }
142 return $min;
143}
144
14516µs1;
146__END__
 
# spent 2µs within URI::_punycode::CORE:qr which was called: # once (2µs+0s) by URI::_idna::BEGIN@7 at line 23
sub URI::_punycode::CORE:qr; # opcode