← Index
NYTProf Performance Profile   « block view • line view • sub view »
For -e
  Run on Sun Aug 5 15:24:32 2012
Reported on Sun Aug 5 15:24:52 2012

Filename/usr/lib/perl5/5.12.4/constant.pm
StatementsExecuted 411 statements in 8.97ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
161633.10ms3.79msconstant::::importconstant::import
1941267µs267µsconstant::::CORE:regcompconstant::CORE:regcomp (opcode)
111240µs240µsconstant::::BEGIN@2constant::BEGIN@2
1611232µs232µsconstant::::CORE:matchconstant::CORE:match (opcode)
11163µs63µsconstant::::BEGIN@25constant::BEGIN@25
11153µs138µsconstant::::BEGIN@114constant::BEGIN@114
11150µs136µsconstant::::BEGIN@52constant::BEGIN@52
11150µs75µsconstant::::BEGIN@3constant::BEGIN@3
11149µs139µsconstant::::BEGIN@29constant::BEGIN@29
11148µs279µsconstant::::BEGIN@6constant::BEGIN@6
11147µs656µsconstant::::BEGIN@4constant::BEGIN@4
33146µs46µsconstant::::CORE:qrconstant::CORE:qr (opcode)
0000s0sconstant::::__ANON__[:130]constant::__ANON__[:130]
0000s0sconstant::::__ANON__[:134]constant::__ANON__[:134]
0000s0sconstant::::__ANON__[:136]constant::__ANON__[:136]
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;
23318µs1240µs
# spent 240µs within constant::BEGIN@2 which was called: # once (240µs+0s) by DateTime::Duration::BEGIN@23 at line 2
use 5.005;
# spent 240µs making 1 call to constant::BEGIN@2
33134µs2101µs
# spent 75µs (50+26) within constant::BEGIN@3 which was called: # once (50µs+26µs) by DateTime::Duration::BEGIN@23 at line 3
use strict;
# spent 75µs making 1 call to constant::BEGIN@3 # spent 26µs making 1 call to strict::import
43158µs21.26ms
# spent 656µs (47+609) within constant::BEGIN@4 which was called: # once (47µs+609µs) by DateTime::Duration::BEGIN@23 at line 4
use warnings::register;
# spent 656µs making 1 call to constant::BEGIN@4 # spent 609µs making 1 call to warnings::register::import
5
63697µs2511µs
# spent 279µs (48+232) within constant::BEGIN@6 which was called: # once (48µs+232µs) by DateTime::Duration::BEGIN@23 at line 6
use vars qw($VERSION %declared);
# spent 279µs making 1 call to constant::BEGIN@6 # spent 232µs making 1 call to vars::import
717µs$VERSION = '1.20';
8
9#=======================================================================
10
11# Some names are evil choices.
12135µsmy %keywords = map +($_, 1), qw{ BEGIN INIT CHECK END DESTROY AUTOLOAD };
1319µs$keywords{UNITCHECK}++ if $] > 5.009;
14
15136µsmy %forced_into_main = map +($_, 1),
16 qw{ STDIN STDOUT STDERR ARGV ARGVOUT ENV INC SIG };
17
18127µsmy %forbidden = (%keywords, %forced_into_main);
19
2017µsmy $str_end = $] >= 5.006 ? "\\z" : "\\Z";
211165µs298µsmy $normal_constant_name = qr/^_?[^\W_0-9]\w*$str_end/;
# spent 71µs making 1 call to constant::CORE:regcomp # spent 26µs making 1 call to constant::CORE:qr
22173µs240µsmy $tolerable = qr/^[A-Za-z_]\w*$str_end/;
# spent 31µs making 1 call to constant::CORE:regcomp # spent 10µs making 1 call to constant::CORE:qr
23173µs241µsmy $boolean = qr/^[01]?$str_end/;
# spent 31µs making 1 call to constant::CORE:regcomp # spent 10µs making 1 call to constant::CORE:qr
24
25
# spent 63µs within constant::BEGIN@25 which was called: # once (63µs+0s) by DateTime::Duration::BEGIN@23 at line 32
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.
293250µs2229µs
# spent 139µs (49+90) within constant::BEGIN@29 which was called: # once (49µs+90µs) by DateTime::Duration::BEGIN@23 at line 29
no strict 'refs';
# spent 139µs making 1 call to constant::BEGIN@29 # spent 90µs making 1 call to strict::unimport
30263µs my $const = $] > 5.009002;
31 *_CAN_PCS = sub () {$const};
321361µs163µs}
# spent 63µs making 1 call to constant::BEGIN@25
33
34#=======================================================================
35# import() - import symbols into user's namespace
36#
37# What we actually do is define a function in the caller's namespace
38# which returns the value. The function we create will normally
39# be inlined as a constant, thereby avoiding further sub calling
40# overhead.
41#=======================================================================
42
# spent 3.79ms (3.10+690µs) within constant::import which was called 16 times, avg 237µs/call: # once (248µs+58µs) by DateTime::Duration::BEGIN@23 at line 23 of DateTime/Duration.pm # once (230µs+60µs) by DateTime::TimeZone::BEGIN@17 at line 17 of DateTime/TimeZone.pm # once (202µs+52µs) by DateTime::BEGIN@72 at line 72 of DateTime.pm # once (199µs+47µs) by DateTime::TimeZone::BEGIN@27 at line 27 of DateTime/TimeZone.pm # once (194µs+48µs) by DateTime::TimeZone::BEGIN@23 at line 23 of DateTime/TimeZone.pm # once (182µs+50µs) by DateTime::TimeZone::BEGIN@21 at line 21 of DateTime/TimeZone.pm # once (209µs+22µs) by DateTime::BEGIN@74 at line 74 of DateTime.pm # once (182µs+48µs) by DateTime::TimeZone::BEGIN@25 at line 25 of DateTime/TimeZone.pm # once (182µs+47µs) by DateTime::TimeZone::BEGIN@18 at line 18 of DateTime/TimeZone.pm # once (187µs+41µs) by DateTime::BEGIN@78 at line 78 of DateTime.pm # once (186µs+38µs) by DateTime::BEGIN@80 at line 80 of DateTime.pm # once (179µs+45µs) by DateTime::TimeZone::BEGIN@24 at line 24 of DateTime/TimeZone.pm # once (178µs+45µs) by DateTime::TimeZone::BEGIN@22 at line 22 of DateTime/TimeZone.pm # once (176µs+45µs) by DateTime::TimeZone::BEGIN@26 at line 26 of DateTime/TimeZone.pm # once (185µs+23µs) by DateTime::BEGIN@75 at line 75 of DateTime.pm # once (174µs+21µs) by DateTime::BEGIN@76 at line 76 of DateTime.pm
sub import {
431761.51ms my $class = shift;
44 return unless @_; # Ignore 'use constant;'
45 my $constants;
46 my $multiple = ref $_[0];
47 my $pkg = caller;
48 my $flush_mro;
49 my $symtab;
50
5116156µs if (_CAN_PCS) {
5231.44ms2223µs
# spent 136µs (50+87) within constant::BEGIN@52 which was called: # once (50µs+87µs) by DateTime::Duration::BEGIN@23 at line 52
no strict 'refs';
# spent 136µs making 1 call to constant::BEGIN@52 # spent 87µs making 1 call to strict::unimport
53 $symtab = \%{$pkg . '::'};
54 };
55
5632198µs if ( $multiple ) {
57 if (ref $_[0] ne 'HASH') {
58 require Carp;
59 Carp::croak("Invalid reference type '".ref(shift)."' not 'HASH'");
60 }
61 $constants = shift;
62 } else {
63 unless (defined $_[0]) {
64 require Carp;
65 Carp::croak("Can't use undef as constant name");
66 }
67 $constants->{+shift} = undef;
68 }
69
70 foreach my $name ( keys %$constants ) {
71 # Normal constant name
7232988µs32366µs if ($name =~ $normal_constant_name and !$forbidden{$name}) {
# spent 232µs making 16 calls to constant::CORE:match, avg 15µs/call # spent 134µs making 16 calls to constant::CORE:regcomp, avg 8µs/call
73 # Everything is okay
74
75 # Name forced into main, but we're not in main. Fatal.
76 } elsif ($forced_into_main{$name} and $pkg ne 'main') {
77 require Carp;
78 Carp::croak("Constant name '$name' is forced into main::");
79
80 # Starts with double underscore. Fatal.
81 } elsif ($name =~ /^__/) {
82 require Carp;
83 Carp::croak("Constant name '$name' begins with '__'");
84
85 # Maybe the name is tolerable
86 } elsif ($name =~ $tolerable) {
87 # Then we'll warn only if you've asked for warnings
88 if (warnings::enabled()) {
89 if ($keywords{$name}) {
90 warnings::warn("Constant name '$name' is a Perl keyword");
91 } elsif ($forced_into_main{$name}) {
92 warnings::warn("Constant name '$name' is " .
93 "forced into package main::");
94 }
95 }
96
97 # Looks like a boolean
98 # use constant FRED == fred;
99 } elsif ($name =~ $boolean) {
100 require Carp;
101 if (@_) {
102 Carp::croak("Constant name '$name' is invalid");
103 } else {
104 Carp::croak("Constant name looks like boolean value");
105 }
106
107 } else {
108 # Must have bad characters
109 require Carp;
110 Carp::croak("Constant name '$name' has invalid characters");
111 }
112
113 {
11431.11ms2224µs
# spent 138µs (53+86) within constant::BEGIN@114 which was called: # once (53µs+86µs) by DateTime::Duration::BEGIN@23 at line 114
no strict 'refs';
# spent 138µs making 1 call to constant::BEGIN@114 # spent 86µs making 1 call to strict::unimport
11548314µs my $full_name = "${pkg}::$name";
116 $declared{$full_name}++;
11732201µs if ($multiple || @_ == 1) {
118 my $scalar = $multiple ? $constants->{$name} : $_[0];
119 # The constant serves to optimise this entire block out on
120 # 5.8 and earlier.
12142584µs if (_CAN_PCS && $symtab && !exists $symtab->{$name}) {
122 # No typeglob yet, so we can use a reference as space-
123 # efficient proxy for a constant subroutine
124 # The check in Perl_ck_rvconst knows that inlinable
125 # constants from cv_const_sv are read only. So we have to:
12613115µs Internals::SvREADONLY($scalar, 1);
# spent 115µs making 13 calls to Internals::SvREADONLY, avg 9µs/call
127 $symtab->{$name} = \$scalar;
128 ++$flush_mro;
129 } else {
130 *$full_name = sub () { $scalar };
131 }
132 } elsif (@_) {
133 my @list = @_;
134 *$full_name = sub () { @list };
135 } else {
136 *$full_name = sub () { };
137 }
138 }
139 }
140 # Flush the cache exactly once if we make any direct symbol table changes.
14113209µs mro::method_changed_in($pkg) if _CAN_PCS && $flush_mro;
# spent 209µs making 13 calls to mro::method_changed_in, avg 16µs/call
142}
143
144152µs1;
145
146__END__
 
# spent 232µs within constant::CORE:match which was called 16 times, avg 15µs/call: # 16 times (232µs+0s) by constant::import at line 72, avg 15µs/call
sub constant::CORE:match; # opcode
# spent 46µs within constant::CORE:qr which was called 3 times, avg 15µs/call: # once (26µs+0s) by DateTime::Duration::BEGIN@23 at line 21 # once (10µs+0s) by DateTime::Duration::BEGIN@23 at line 23 # once (10µs+0s) by DateTime::Duration::BEGIN@23 at line 22
sub constant::CORE:qr; # opcode
# spent 267µs within constant::CORE:regcomp which was called 19 times, avg 14µs/call: # 16 times (134µs+0s) by constant::import at line 72, avg 8µs/call # once (71µs+0s) by DateTime::Duration::BEGIN@23 at line 21 # once (31µs+0s) by DateTime::Duration::BEGIN@23 at line 23 # once (31µs+0s) by DateTime::Duration::BEGIN@23 at line 22
sub constant::CORE:regcomp; # opcode