← Index
NYTProf Performance Profile   « line view »
For t/optimization.t
  Run on Thu Jan 8 22:47:42 2015
Reported on Thu Jan 8 22:48:05 2015

Filename/home/ss5/perl5/perlbrew/perls/tapper-perl/lib/5.16.3/constant.pm
StatementsExecuted 319 statements in 1.93ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
444341µs426µsconstant::::importconstant::import
111188µs13.1msconstant::::BEGIN@25constant::BEGIN@25
111184µs184µsconstant::::BEGIN@36constant::BEGIN@36
264148µs48µsconstant::::CORE:regcompconstant::CORE:regcomp (opcode)
231141µs41µsconstant::::CORE:matchconstant::CORE:match (opcode)
11118µs18µsconstant::::BEGIN@2constant::BEGIN@2
11114µs31µsconstant::::BEGIN@65constant::BEGIN@65
11113µs151µsconstant::::BEGIN@4constant::BEGIN@4
11112µs28µsconstant::::BEGIN@3constant::BEGIN@3
11112µs54µsconstant::::BEGIN@6constant::BEGIN@6
11110µs22µsconstant::::BEGIN@127constant::BEGIN@127
11110µs24µsconstant::::BEGIN@29constant::BEGIN@29
3318µs8µsconstant::::CORE:qrconstant::CORE:qr (opcode)
0000s0sconstant::::__ANON__[:151]constant::__ANON__[:151]
0000s0sconstant::::__ANON__[:155]constant::__ANON__[:155]
0000s0sconstant::::__ANON__[:157]constant::__ANON__[:157]
0000s0sconstant::::__ANON__[:31]constant::__ANON__[:31]
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package constant;
2253µs118µs
# spent 18µs within constant::BEGIN@2 which was called: # once (18µs+0s) by Data::Dumper::BEGIN@270 at line 2
use 5.005;
# spent 18µs making 1 call to constant::BEGIN@2
3230µs244µs
# spent 28µs (12+16) within constant::BEGIN@3 which was called: # once (12µs+16µs) by Data::Dumper::BEGIN@270 at line 3
use strict;
# spent 28µs making 1 call to constant::BEGIN@3 # spent 16µs making 1 call to strict::import
4235µs2288µs
# spent 151µs (13+138) within constant::BEGIN@4 which was called: # once (13µs+138µs) by Data::Dumper::BEGIN@270 at line 4
use warnings::register;
# spent 151µs making 1 call to constant::BEGIN@4 # spent 138µs making 1 call to warnings::register::import
5
62127µs297µs
# spent 54µs (12+43) within constant::BEGIN@6 which was called: # once (12µs+43µs) by Data::Dumper::BEGIN@270 at line 6
use vars qw($VERSION %declared);
# spent 54µs making 1 call to constant::BEGIN@6 # spent 43µs making 1 call to vars::import
71600ns$VERSION = '1.23';
8
9#=======================================================================
10
11# Some names are evil choices.
1217µsmy %keywords = map +($_, 1), qw{ BEGIN INIT CHECK END DESTROY AUTOLOAD };
1312µs$keywords{UNITCHECK}++ if $] > 5.009;
14
1516µsmy %forced_into_main = map +($_, 1),
16 qw{ STDIN STDOUT STDERR ARGV ARGVOUT ENV INC SIG };
17
1817µsmy %forbidden = (%keywords, %forced_into_main);
19
201800nsmy $str_end = $] >= 5.006 ? "\\z" : "\\Z";
21138µs225µsmy $normal_constant_name = qr/^_?[^\W_0-9]\w*$str_end/;
# spent 19µs making 1 call to constant::CORE:regcomp # spent 6µs making 1 call to constant::CORE:qr
22113µs27µsmy $tolerable = qr/^[A-Za-z_]\w*$str_end/;
# spent 6µs making 1 call to constant::CORE:regcomp # spent 1µs making 1 call to constant::CORE:qr
23112µs26µsmy $boolean = qr/^[01]?$str_end/;
# spent 5µs making 1 call to constant::CORE:regcomp # spent 1µs making 1 call to constant::CORE:qr
24
25
# spent 13.1ms (188µs+12.9) within constant::BEGIN@25 which was called: # once (188µs+12.9ms) by Data::Dumper::BEGIN@270 at line 45
BEGIN {
26 # We'd like to do use constant _CAN_PCS => $] > 5.009002
27 # but that's a bit tricky before we load the constant module :-)
28 # By doing this, we save 1 run time check for *every* call to import.
292155µs238µs
# spent 24µs (10+14) within constant::BEGIN@29 which was called: # once (10µs+14µs) by Data::Dumper::BEGIN@270 at line 29
no strict 'refs';
# spent 24µs making 1 call to constant::BEGIN@29 # spent 14µs making 1 call to strict::unimport
3012µs my $const = $] > 5.009002;
3116µs *_CAN_PCS = sub () {$const};
32
33 # Before this makes its way into a dev perl release, we have to do
34 # browser-sniffing, as it were....
351200ns return unless $const;
363326µs13.09ms
# spent 184µs within constant::BEGIN@36 which was called: # once (184µs+0s) by constant::BEGIN@25 at line 45
*{chr 256} = \3;
# spent 3.09ms making 1 call to utf8::AUTOLOAD
3716µs if (exists ${__PACKAGE__."::"}{"\xc4\x80"}) {
38 delete ${__PACKAGE__."::"}{"\xc4\x80"};
39 *_DOWNGRADE = sub () {1};
40 }
41 else {
4213µs delete ${__PACKAGE__."::"}{chr 256};
4312µs *_DOWNGRADE = sub () {0};
44 }
451103µs213.3ms}
# spent 13.1ms making 1 call to constant::BEGIN@25 # spent 184µs making 1 call to constant::BEGIN@36
46
47#=======================================================================
48# import() - import symbols into user's namespace
49#
50# What we actually do is define a function in the caller's namespace
51# which returns the value. The function we create will normally
52# be inlined as a constant, thereby avoiding further sub calling
53# overhead.
54#=======================================================================
55
# spent 426µs (341+84) within constant::import which was called 4 times, avg 106µs/call: # once (141µs+33µs) by Data::DPath::Context::BEGIN@52 at line 52 of lib/Data/DPath/Context.pm # once (107µs+27µs) by Data::DPath::Path::BEGIN@21 at line 21 of lib/Data/DPath/Path.pm # once (51µs+14µs) by Data::DPath::Filters::BEGIN@9 at line 10 of lib/Data/DPath/Filters.pm # once (42µs+10µs) by Data::Dumper::BEGIN@270 at line 270 of Data/Dumper.pm
sub import {
5643µs my $class = shift;
5742µs return unless @_; # Ignore 'use constant;'
584900ns my $constants;
5944µs my $multiple = ref $_[0];
6043µs my $pkg = caller;
614700ns my $flush_mro;
624700ns my $symtab;
63
6442µs if (_CAN_PCS) {
652271µs249µs
# spent 31µs (14+18) within constant::BEGIN@65 which was called: # once (14µs+18µs) by Data::Dumper::BEGIN@270 at line 65
no strict 'refs';
# spent 31µs making 1 call to constant::BEGIN@65 # spent 18µs making 1 call to strict::unimport
6648µs $symtab = \%{$pkg . '::'};
67 };
68
6942µs if ( $multiple ) {
7032µs if (ref $_[0] ne 'HASH') {
71 require Carp;
72 Carp::croak("Invalid reference type '".ref(shift)."' not 'HASH'");
73 }
7431µs $constants = shift;
75 } else {
761400ns unless (defined $_[0]) {
77 require Carp;
78 Carp::croak("Can't use undef as constant name");
79 }
8011µs $constants->{+shift} = undef;
81 }
82
83412µs foreach my $name ( keys %$constants ) {
84 # Normal constant name
8523158µs4659µs if ($name =~ $normal_constant_name and !$forbidden{$name}) {
# spent 41µs making 23 calls to constant::CORE:match, avg 2µs/call # spent 18µs making 23 calls to constant::CORE:regcomp, avg 787ns/call
86 # Everything is okay
87
88 # Name forced into main, but we're not in main. Fatal.
89 } elsif ($forced_into_main{$name} and $pkg ne 'main') {
90 require Carp;
91 Carp::croak("Constant name '$name' is forced into main::");
92
93 # Starts with double underscore. Fatal.
94 } elsif ($name =~ /^__/) {
95 require Carp;
96 Carp::croak("Constant name '$name' begins with '__'");
97
98 # Maybe the name is tolerable
99 } elsif ($name =~ $tolerable) {
100 # Then we'll warn only if you've asked for warnings
101 if (warnings::enabled()) {
102 if ($keywords{$name}) {
103 warnings::warn("Constant name '$name' is a Perl keyword");
104 } elsif ($forced_into_main{$name}) {
105 warnings::warn("Constant name '$name' is " .
106 "forced into package main::");
107 }
108 }
109
110 # Looks like a boolean
111 # use constant FRED == fred;
112 } elsif ($name =~ $boolean) {
113 require Carp;
114 if (@_) {
115 Carp::croak("Constant name '$name' is invalid");
116 } else {
117 Carp::croak("Constant name looks like boolean value");
118 }
119
120 } else {
121 # Must have bad characters
122 require Carp;
123 Carp::croak("Constant name '$name' has invalid characters");
124 }
125
126 {
12725301µs235µs
# spent 22µs (10+13) within constant::BEGIN@127 which was called: # once (10µs+13µs) by Data::Dumper::BEGIN@270 at line 127
no strict 'refs';
# spent 22µs making 1 call to constant::BEGIN@127 # spent 13µs making 1 call to strict::unimport
1282318µs my $full_name = "${pkg}::$name";
1292322µs $declared{$full_name}++;
1302311µs if ($multiple || @_ == 1) {
1312312µs my $scalar = $multiple ? $constants->{$name} : $_[0];
132
133 if (_DOWNGRADE) { # for 5.10 to 5.14
134 # Work around perl bug #31991: Sub names (actually glob
135 # names in general) ignore the UTF8 flag. So we have to
136 # turn it off to get the "right" symbol table entry.
137 utf8::is_utf8 $name and utf8::encode $name;
138 }
139
140 # The constant serves to optimise this entire block out on
141 # 5.8 and earlier.
1422318µs if (_CAN_PCS && $symtab && !exists $symtab->{$name}) {
143 # No typeglob yet, so we can use a reference as space-
144 # efficient proxy for a constant subroutine
145 # The check in Perl_ck_rvconst knows that inlinable
146 # constants from cv_const_sv are read only. So we have to:
1472372µs2318µs Internals::SvREADONLY($scalar, 1);
# spent 18µs making 23 calls to Internals::SvREADONLY, avg 791ns/call
1482317µs $symtab->{$name} = \$scalar;
149238µs ++$flush_mro;
150 } else {
151 *$full_name = sub () { $scalar };
152 }
153 } elsif (@_) {
154 my @list = @_;
155 *$full_name = sub () { @list };
156 } else {
157 *$full_name = sub () { };
158 }
159 }
160 }
161 # Flush the cache exactly once if we make any direct symbol table changes.
162439µs47µs mro::method_changed_in($pkg) if _CAN_PCS && $flush_mro;
# spent 7µs making 4 calls to mro::method_changed_in, avg 2µs/call
163}
164
165112µs1;
166
167__END__
 
# spent 41µs within constant::CORE:match which was called 23 times, avg 2µs/call: # 23 times (41µs+0s) by constant::import at line 85, avg 2µs/call
sub constant::CORE:match; # opcode
# spent 8µs within constant::CORE:qr which was called 3 times, avg 3µs/call: # once (6µs+0s) by Data::Dumper::BEGIN@270 at line 21 # once (1µs+0s) by Data::Dumper::BEGIN@270 at line 22 # once (1µs+0s) by Data::Dumper::BEGIN@270 at line 23
sub constant::CORE:qr; # opcode
# spent 48µs within constant::CORE:regcomp which was called 26 times, avg 2µs/call: # 23 times (18µs+0s) by constant::import at line 85, avg 787ns/call # once (19µs+0s) by Data::Dumper::BEGIN@270 at line 21 # once (6µs+0s) by Data::Dumper::BEGIN@270 at line 22 # once (5µs+0s) by Data::Dumper::BEGIN@270 at line 23
sub constant::CORE:regcomp; # opcode