← Index
NYTProf Performance Profile   « line view »
For rbm/rbm
  Run on Wed Feb 12 20:36:06 2020
Reported on Wed Feb 12 21:42:25 2020

Filename/usr/share/perl/5.28/constant.pm
StatementsExecuted 2558 statements in 4.02ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
8181151.92ms2.43msconstant::::importconstant::import
111179µs210µsconstant::::BEGIN@4constant::BEGIN@4
8711158µs158µsconstant::::CORE:matchconstant::CORE:match (opcode)
8711140µs140µsconstant::::CORE:substconstant::CORE:subst (opcode)
8711104µs104µsconstant::::CORE:regcompconstant::CORE:regcomp (opcode)
11116µs16µsconstant::::BEGIN@2constant::BEGIN@2
11113µs14µsconstant::::BEGIN@24constant::BEGIN@24
1116µs15µsconstant::::BEGIN@40constant::BEGIN@40
1116µs8µsconstant::::BEGIN@3constant::BEGIN@3
1116µs14µsconstant::::BEGIN@141constant::BEGIN@141
1116µs13µsconstant::::BEGIN@90constant::BEGIN@90
1115µs12µsconstant::::BEGIN@65constant::BEGIN@65
3313µs3µsconstant::::CORE:qrconstant::CORE:qr (opcode)
0000s0sconstant::::__ANON__[:174]constant::__ANON__[:174]
0000s0sconstant::::__ANON__[:190]constant::__ANON__[:190]
0000s0sconstant::::__ANON__[:192]constant::__ANON__[:192]
0000s0sconstant::::__ANON__[:41]constant::__ANON__[:41]
0000s0sconstant::::__ANON__[:42]constant::__ANON__[:42]
0000s0sconstant::::__ANON__[:43]constant::__ANON__[:43]
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package constant;
2240µs116µs
# spent 16µs within constant::BEGIN@2 which was called: # once (16µs+0s) by File::Spec::Unix::BEGIN@57 at line 2
use 5.008;
# spent 16µs making 1 call to constant::BEGIN@2
3219µs210µs
# spent 8µs (6+2) within constant::BEGIN@3 which was called: # once (6µs+2µs) by File::Spec::Unix::BEGIN@57 at line 3
use strict;
# spent 8µs making 1 call to constant::BEGIN@3 # spent 2µs making 1 call to strict::import
42413µs2242µs
# spent 210µs (179+31) within constant::BEGIN@4 which was called: # once (179µs+31µs) by File::Spec::Unix::BEGIN@57 at line 4
use warnings::register;
# spent 210µs making 1 call to constant::BEGIN@4 # spent 31µs making 1 call to warnings::register::import
5
61400nsour $VERSION = '1.33';
7our %declared;
8
9#=======================================================================
10
11# Some names are evil choices.
1215µsmy %keywords = map +($_, 1), qw{ BEGIN INIT CHECK END DESTROY AUTOLOAD };
1311µs$keywords{UNITCHECK}++ if $] > 5.009;
14
1514µsmy %forced_into_main = map +($_, 1),
16 qw{ STDIN STDOUT STDERR ARGV ARGVOUT ENV INC SIG };
17
1815µsmy %forbidden = (%keywords, %forced_into_main);
19
2017µs12µsmy $normal_constant_name = qr/^_?[^\W_0-9]\w*\z/;
# spent 2µs making 1 call to constant::CORE:qr
2112µs1600nsmy $tolerable = qr/^[A-Za-z_]\w*\z/;
# spent 600ns making 1 call to constant::CORE:qr
2212µs1500nsmy $boolean = qr/^[01]?\z/;
# spent 500ns making 1 call to constant::CORE:qr
23
24
# spent 14µs (13+1) within constant::BEGIN@24 which was called: # once (13µs+1µs) by File::Spec::Unix::BEGIN@57 at line 45
BEGIN {
25 # We'd like to do use constant _CAN_PCS => $] > 5.009002
26 # but that's a bit tricky before we load the constant module :-)
27 # By doing this, we save several run time checks for *every* call
28 # to import.
291800ns my $const = $] > 5.009002;
301400ns my $downgrade = $] < 5.015004; # && $] >= 5.008
311500ns my $constarray = exists &_make_const;
3212µs if ($const) {
3315µs1800ns Internals::SvREADONLY($const, 1);
# spent 800ns making 1 call to Internals::SvREADONLY
3412µs1300ns Internals::SvREADONLY($downgrade, 1);
# spent 300ns making 1 call to Internals::SvREADONLY
351500ns $constant::{_CAN_PCS} = \$const;
3611µs $constant::{_DOWNGRADE} = \$downgrade;
371400ns $constant::{_CAN_PCS_FOR_ARRAY} = \$constarray;
38 }
39 else {
40276µs225µs
# spent 15µs (6+9) within constant::BEGIN@40 which was called: # once (6µs+9µs) by File::Spec::Unix::BEGIN@57 at line 40
no strict 'refs';
# spent 15µs making 1 call to constant::BEGIN@40 # spent 9µs making 1 call to strict::unimport
41 *{"_CAN_PCS"} = sub () {$const};
42 *{"_DOWNGRADE"} = sub () { $downgrade };
43 *{"_CAN_PCS_FOR_ARRAY"} = sub () { $constarray };
44 }
45166µs114µs}
# spent 14µs making 1 call to constant::BEGIN@24
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 2.43ms (1.92+503µs) within constant::import which was called 81 times, avg 30µs/call: # once (97µs+33µs) by Path::Tiny::BEGIN@19 at line 20 of Path/Tiny.pm # once (86µs+12µs) by Template::Iterator::BEGIN@31 at line 31 of Template/Iterator.pm # once (76µs+5µs) by File::Temp::BEGIN@86 at line 86 of File/Temp.pm # once (53µs+18µs) by Template::Parser::BEGIN@44 at line 44 of Template/Parser.pm # once (20µs+46µs) by Template::Iterator::BEGIN@32 at line 32 of Template/Iterator.pm # once (52µs+13µs) by Getopt::Long::BEGIN@220 at line 220 of Getopt/Long.pm # once (49µs+14µs) by Template::Context::BEGIN@33 at line 33 of Template/Context.pm # once (48µs+12µs) by File::Temp::BEGIN@83 at line 83 of File/Temp.pm # once (46µs+12µs) by Encode::Encoding::BEGIN@14 at line 14 of Encode/Encoding.pm # once (46µs+11µs) by Encode::BEGIN@7 at line 7 of Encode.pm # once (42µs+11µs) by YAML::XS::BEGIN@99 at line 116 of YAML/XS.pm # once (40µs+11µs) by Getopt::Long::BEGIN@259 at line 259 of Getopt/Long.pm # once (38µs+8µs) by Template::Exception::BEGIN@24 at line 24 of Template/Exception.pm # once (28µs+11µs) by File::Spec::Unix::BEGIN@57 at line 57 of File/Spec/Unix.pm # once (27µs+8µs) by Template::Provider::BEGIN@50 at line 50 of Template/Provider.pm # once (25µs+7µs) by Encode::Alias::BEGIN@5 at line 5 of Encode/Alias.pm # once (24µs+4µs) by Template::Constants::BEGIN@73 at line 73 of Template/Constants.pm # once (22µs+6µs) by Template::Constants::BEGIN@40 at line 40 of Template/Constants.pm # once (22µs+5µs) by Getopt::Long::BEGIN@234 at line 234 of Getopt/Long.pm # once (20µs+6µs) by Template::Service::BEGIN@31 at line 31 of Template/Service.pm # once (21µs+6µs) by File::Spec::Unix::BEGIN@119 at line 119 of File/Spec/Unix.pm # once (22µs+4µs) by Getopt::Long::BEGIN@249 at line 249 of Getopt/Long.pm # once (20µs+5µs) by File::Spec::Unix::BEGIN@127 at line 127 of File/Spec/Unix.pm # once (19µs+5µs) by File::Spec::Unix::BEGIN@60 at line 60 of File/Spec/Unix.pm # once (20µs+4µs) by Template::Context::BEGIN@34 at line 34 of Template/Context.pm # once (19µs+5µs) by Template::Parser::BEGIN@45 at line 45 of Template/Parser.pm # once (20µs+4µs) by Getopt::Long::BEGIN@235 at line 235 of Getopt/Long.pm # once (19µs+4µs) by Template::Provider::BEGIN@52 at line 52 of Template/Provider.pm # once (19µs+5µs) by Getopt::Long::BEGIN@230 at line 230 of Getopt/Long.pm # once (20µs+4µs) by Template::Constants::BEGIN@67 at line 67 of Template/Constants.pm # once (18µs+5µs) by File::Temp::BEGIN@90 at line 90 of File/Temp.pm # once (19µs+4µs) by Template::Constants::BEGIN@74 at line 74 of Template/Constants.pm # once (18µs+5µs) by Template::Exception::BEGIN@25 at line 25 of Template/Exception.pm # once (18µs+5µs) by Template::Constants::BEGIN@45 at line 45 of Template/Constants.pm # once (19µs+4µs) by Template::Constants::BEGIN@59 at line 59 of Template/Constants.pm # once (19µs+4µs) by Template::Constants::BEGIN@64 at line 64 of Template/Constants.pm # once (18µs+5µs) by File::Spec::Unix::BEGIN@63 at line 63 of File/Spec/Unix.pm # once (18µs+4µs) by Template::Parser::BEGIN@46 at line 46 of Template/Parser.pm # once (18µs+4µs) by Template::Constants::BEGIN@69 at line 69 of Template/Constants.pm # once (18µs+4µs) by File::Temp::BEGIN@95 at line 95 of File/Temp.pm # once (18µs+4µs) by Template::Context::BEGIN@35 at line 35 of Template/Context.pm # once (18µs+4µs) by Getopt::Long::BEGIN@232 at line 232 of Getopt/Long.pm # once (18µs+4µs) by Template::Provider::BEGIN@51 at line 51 of Template/Provider.pm # once (18µs+4µs) by Template::Constants::BEGIN@42 at line 42 of Template/Constants.pm # once (17µs+4µs) by Template::Constants::BEGIN@50 at line 50 of Template/Constants.pm # once (17µs+5µs) by Template::Constants::BEGIN@68 at line 68 of Template/Constants.pm # once (18µs+4µs) by Getopt::Long::BEGIN@236 at line 236 of Getopt/Long.pm # once (18µs+4µs) by Template::Parser::BEGIN@47 at line 47 of Template/Parser.pm # once (17µs+4µs) by Template::Constants::BEGIN@54 at line 54 of Template/Constants.pm # once (17µs+4µs) by Template::Constants::BEGIN@51 at line 51 of Template/Constants.pm # once (17µs+4µs) by Getopt::Long::BEGIN@238 at line 238 of Getopt/Long.pm # once (17µs+4µs) by Template::Exception::BEGIN@26 at line 26 of Template/Exception.pm # once (17µs+4µs) by Template::Constants::BEGIN@41 at line 41 of Template/Constants.pm # once (17µs+4µs) by Template::Constants::BEGIN@43 at line 43 of Template/Constants.pm # once (17µs+4µs) by Template::Constants::BEGIN@49 at line 49 of Template/Constants.pm # once (17µs+4µs) by Getopt::Long::BEGIN@240 at line 240 of Getopt/Long.pm # once (17µs+4µs) by Template::Provider::BEGIN@53 at line 53 of Template/Provider.pm # once (16µs+4µs) by Template::Constants::BEGIN@70 at line 70 of Template/Constants.pm # once (17µs+4µs) by Template::Constants::BEGIN@48 at line 48 of Template/Constants.pm # once (17µs+4µs) by Template::Constants::BEGIN@53 at line 53 of Template/Constants.pm # once (16µs+4µs) by Template::Constants::BEGIN@52 at line 52 of Template/Constants.pm # once (17µs+4µs) by Getopt::Long::BEGIN@241 at line 241 of Getopt/Long.pm # once (16µs+4µs) by Getopt::Long::BEGIN@248 at line 248 of Getopt/Long.pm # once (16µs+4µs) by File::Temp::BEGIN@94 at line 94 of File/Temp.pm # once (17µs+4µs) by Template::Provider::BEGIN@55 at line 55 of Template/Provider.pm # once (16µs+4µs) by Template::Constants::BEGIN@58 at line 58 of Template/Constants.pm # once (16µs+4µs) by File::Temp::BEGIN@96 at line 96 of File/Temp.pm # once (16µs+4µs) by Template::Constants::BEGIN@79 at line 79 of Template/Constants.pm # once (16µs+4µs) by Template::Constants::BEGIN@44 at line 44 of Template/Constants.pm # once (16µs+4µs) by Template::Constants::BEGIN@60 at line 60 of Template/Constants.pm # once (16µs+4µs) by Template::Constants::BEGIN@75 at line 75 of Template/Constants.pm # once (16µs+4µs) by Template::Constants::BEGIN@71 at line 71 of Template/Constants.pm # once (16µs+4µs) by Template::Provider::BEGIN@54 at line 54 of Template/Provider.pm # once (16µs+4µs) by Template::Constants::BEGIN@57 at line 57 of Template/Constants.pm # once (16µs+4µs) by Template::Constants::BEGIN@65 at line 65 of Template/Constants.pm # once (16µs+4µs) by Template::Constants::BEGIN@72 at line 72 of Template/Constants.pm # once (15µs+4µs) by Getopt::Long::BEGIN@237 at line 237 of Getopt/Long.pm # once (16µs+4µs) by Template::Constants::BEGIN@80 at line 80 of Template/Constants.pm # once (16µs+4µs) by Template::Constants::BEGIN@66 at line 66 of Template/Constants.pm # once (16µs+4µs) by Template::Constants::BEGIN@61 at line 61 of Template/Constants.pm # once (15µs+4µs) by Template::Constants::BEGIN@76 at line 76 of Template/Constants.pm
sub import {
568128µs my $class = shift;
578116µs return unless @_; # Ignore 'use constant;'
58819µs my $constants;
598132µs my $multiple = ref $_[0];
608133µs my $caller = caller;
618116µs my $flush_mro;
62 my $symtab;
63
648127µs if (_CAN_PCS) {
652132µs220µs
# spent 12µs (5+7) within constant::BEGIN@65 which was called: # once (5µs+7µs) by File::Spec::Unix::BEGIN@57 at line 65
no strict 'refs';
# spent 12µs making 1 call to constant::BEGIN@65 # spent 7µs making 1 call to strict::unimport
668185µs $symtab = \%{$caller . '::'};
67 };
68
698126µs if ( $multiple ) {
7011µs if (ref $_[0] ne 'HASH') {
71 require Carp;
72 Carp::croak("Invalid reference type '".ref(shift)."' not 'HASH'");
73 }
741300ns $constants = shift;
75 } else {
768013µs unless (defined $_[0]) {
77 require Carp;
78 Carp::croak("Can't use undef as constant name");
79 }
808079µs $constants->{+shift} = undef;
81 }
82
838191µs foreach my $name ( keys %$constants ) {
848711µs my $pkg;
858714µs my $symtab = $symtab;
868718µs my $orig_name = $name;
8787320µs87140µs if ($name =~ s/(.*)(?:::|')(?=.)//s) {
# spent 140µs making 87 calls to constant::CORE:subst, avg 2µs/call
88 $pkg = $1;
89 if (_CAN_PCS && $pkg ne $caller) {
902238µs220µs
# spent 13µs (6+7) within constant::BEGIN@90 which was called: # once (6µs+7µs) by File::Spec::Unix::BEGIN@57 at line 90
no strict 'refs';
# spent 13µs making 1 call to constant::BEGIN@90 # spent 7µs making 1 call to strict::unimport
91 $symtab = \%{$pkg . '::'};
92 }
93 }
94 else {
958716µs $pkg = $caller;
96 }
97
98 # Normal constant name
9987517µs174262µs if ($name =~ $normal_constant_name and !$forbidden{$name}) {
# spent 158µs making 87 calls to constant::CORE:match, avg 2µs/call # spent 104µs making 87 calls to constant::CORE:regcomp, avg 1µs/call
100 # Everything is okay
101
102 # Name forced into main, but we're not in main. Fatal.
103 } elsif ($forced_into_main{$name} and $pkg ne 'main') {
104 require Carp;
105 Carp::croak("Constant name '$name' is forced into main::");
106
107 # Starts with double underscore. Fatal.
108 } elsif ($name =~ /^__/) {
109 require Carp;
110 Carp::croak("Constant name '$name' begins with '__'");
111
112 # Maybe the name is tolerable
113 } elsif ($name =~ $tolerable) {
114 # Then we'll warn only if you've asked for warnings
115 if (warnings::enabled()) {
116 if ($keywords{$name}) {
117 warnings::warn("Constant name '$name' is a Perl keyword");
118 } elsif ($forced_into_main{$name}) {
119 warnings::warn("Constant name '$name' is " .
120 "forced into package main::");
121 }
122 }
123
124 # Looks like a boolean
125 # use constant FRED == fred;
126 } elsif ($name =~ $boolean) {
127 require Carp;
128 if (@_) {
129 Carp::croak("Constant name '$name' is invalid");
130 } else {
131 Carp::croak("Constant name looks like boolean value");
132 }
133
134 } else {
135 # Must have bad characters
136 require Carp;
137 Carp::croak("Constant name '$name' has invalid characters");
138 }
139
140 {
14189493µs222µs
# spent 14µs (6+8) within constant::BEGIN@141 which was called: # once (6µs+8µs) by File::Spec::Unix::BEGIN@57 at line 141
no strict 'refs';
# spent 14µs making 1 call to constant::BEGIN@141 # spent 8µs making 1 call to strict::unimport
1428731µs my $full_name = "${pkg}::$name";
14387101µs $declared{$full_name}++;
1448749µs if ($multiple || @_ == 1) {
1458727µs my $scalar = $multiple ? $constants->{$orig_name} : $_[0];
146
147 if (_DOWNGRADE) { # for 5.8 to 5.14
148 # Work around perl bug #31991: Sub names (actually glob
149 # names in general) ignore the UTF8 flag. So we have to
150 # turn it off to get the "right" symbol table entry.
151 utf8::is_utf8 $name and utf8::encode $name;
152 }
153
154 # The constant serves to optimise this entire block out on
155 # 5.8 and earlier.
1568721µs if (_CAN_PCS) {
157 # Use a reference as a proxy for a constant subroutine.
158 # If this is not a glob yet, it saves space. If it is
159 # a glob, we must still create it this way to get the
160 # right internal flags set, as constants are distinct
161 # from subroutines created with sub(){...}.
162 # The check in Perl_ck_rvconst knows that inlinable
163 # constants from cv_const_sv are read only. So we have to:
16487242µs8749µs Internals::SvREADONLY($scalar, 1);
# spent 49µs making 87 calls to Internals::SvREADONLY, avg 559ns/call
1658756µs if (!exists $symtab->{$name}) {
1668742µs $symtab->{$name} = \$scalar;
1678753µs ++$flush_mro->{$pkg};
168 }
169 else {
170 local $constant::{_dummy} = \$scalar;
171 *$full_name = \&{"_dummy"};
172 }
173 } else {
174 *$full_name = sub () { $scalar };
175 }
176 } elsif (@_) {
177 my @list = @_;
178 if (_CAN_PCS_FOR_ARRAY) {
179 _make_const($list[$_]) for 0..$#list;
180 _make_const(@list);
181 if (!exists $symtab->{$name}) {
182 $symtab->{$name} = \@list;
183 $flush_mro->{$pkg}++;
184 }
185 else {
186 local $constant::{_dummy} = \@list;
187 *$full_name = \&{"_dummy"};
188 }
189 }
190 else { *$full_name = sub () { @list }; }
191 } else {
192 *$full_name = sub () { };
193 }
194 }
195 }
196 # Flush the cache exactly once if we make any direct symbol table changes.
19781279µs if (_CAN_PCS && $flush_mro) {
19881247µs8153µs mro::method_changed_in($_) for keys %$flush_mro;
# spent 53µs making 81 calls to mro::method_changed_in, avg 656ns/call
199 }
200}
201
20219µs1;
203
204__END__
 
# spent 158µs within constant::CORE:match which was called 87 times, avg 2µs/call: # 87 times (158µs+0s) by constant::import at line 99, avg 2µs/call
sub constant::CORE:match; # opcode
# spent 3µs within constant::CORE:qr which was called 3 times, avg 1µs/call: # once (2µs+0s) by File::Spec::Unix::BEGIN@57 at line 20 # once (600ns+0s) by File::Spec::Unix::BEGIN@57 at line 21 # once (500ns+0s) by File::Spec::Unix::BEGIN@57 at line 22
sub constant::CORE:qr; # opcode
# spent 104µs within constant::CORE:regcomp which was called 87 times, avg 1µs/call: # 87 times (104µs+0s) by constant::import at line 99, avg 1µs/call
sub constant::CORE:regcomp; # opcode
# spent 140µs within constant::CORE:subst which was called 87 times, avg 2µs/call: # 87 times (140µs+0s) by constant::import at line 87, avg 2µs/call
sub constant::CORE:subst; # opcode