← Index
NYTProf Performance Profile   « line view »
For examples/Atom-timer.pl
  Run on Mon Aug 12 14:45:28 2013
Reported on Mon Aug 12 14:46:14 2013

Filename/Users/dde/perl5/perlbrew/perls/5.18.0t/lib/5.18.0/constant.pm
StatementsExecuted 171 statements in 964µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
665135µs174µsconstant::::importconstant::import
11112µs12µsconstant::::BEGIN@2constant::BEGIN@2
11112µs12µsconstant::::BEGIN@24constant::BEGIN@24
61112µs12µsconstant::::CORE:matchconstant::CORE:match (opcode)
61112µs12µsconstant::::CORE:regcompconstant::CORE:regcomp (opcode)
1116µs14µsconstant::::BEGIN@116constant::BEGIN@116
1116µs14µsconstant::::BEGIN@28constant::BEGIN@28
1115µs16µsconstant::::BEGIN@3constant::BEGIN@3
1115µs13µsconstant::::BEGIN@54constant::BEGIN@54
1115µs32µsconstant::::BEGIN@6constant::BEGIN@6
1115µs67µsconstant::::BEGIN@4constant::BEGIN@4
3313µs3µsconstant::::CORE:qrconstant::CORE:qr (opcode)
0000s0sconstant::::__ANON__[:140]constant::__ANON__[:140]
0000s0sconstant::::__ANON__[:144]constant::__ANON__[:144]
0000s0sconstant::::__ANON__[:146]constant::__ANON__[:146]
0000s0sconstant::::__ANON__[:30]constant::__ANON__[:30]
0000s0sconstant::::__ANON__[:33]constant::__ANON__[:33]
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package constant;
2239µs112µs
# spent 12µs within constant::BEGIN@2 which was called: # once (12µs+0s) by Try::Tiny::ScopeGuard::BEGIN@144 at line 2
use 5.008;
# spent 12µs making 1 call to constant::BEGIN@2
3221µs226µs
# spent 16µs (5+10) within constant::BEGIN@3 which was called: # once (5µs+10µs) by Try::Tiny::ScopeGuard::BEGIN@144 at line 3
use strict;
# spent 16µs making 1 call to constant::BEGIN@3 # spent 10µs making 1 call to strict::import
4222µs2128µs
# spent 67µs (5+62) within constant::BEGIN@4 which was called: # once (5µs+62µs) by Try::Tiny::ScopeGuard::BEGIN@144 at line 4
use warnings::register;
# spent 67µs making 1 call to constant::BEGIN@4 # spent 62µs making 1 call to warnings::register::import
5
62114µs259µs
# spent 32µs (5+27) within constant::BEGIN@6 which was called: # once (5µs+27µs) by Try::Tiny::ScopeGuard::BEGIN@144 at line 6
use vars qw($VERSION %declared);
# spent 32µs making 1 call to constant::BEGIN@6 # spent 27µs making 1 call to vars::import
71400ns$VERSION = '1.27';
8
9#=======================================================================
10
11# Some names are evil choices.
1214µsmy %keywords = map +($_, 1), qw{ BEGIN INIT CHECK END DESTROY AUTOLOAD };
131800ns$keywords{UNITCHECK}++ if $] > 5.009;
14
1514µsmy %forced_into_main = map +($_, 1),
16 qw{ STDIN STDOUT STDERR ARGV ARGVOUT ENV INC SIG };
17
1814µsmy %forbidden = (%keywords, %forced_into_main);
19
2016µs12µsmy $normal_constant_name = qr/^_?[^\W_0-9]\w*\z/;
# spent 2µs making 1 call to constant::CORE:qr
2113µs1700nsmy $tolerable = qr/^[A-Za-z_]\w*\z/;
# spent 700ns making 1 call to constant::CORE:qr
2212µs1600nsmy $boolean = qr/^[01]?\z/;
# spent 600ns making 1 call to constant::CORE:qr
23
24
# spent 12µs within constant::BEGIN@24 which was called: # once (12µs+0s) by Try::Tiny::ScopeGuard::BEGIN@144 at line 34
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 1 run time check for *every* call to import.
28264µs222µs
# spent 14µs (6+8) within constant::BEGIN@28 which was called: # once (6µs+8µs) by Try::Tiny::ScopeGuard::BEGIN@144 at line 28
no strict 'refs';
# spent 14µs making 1 call to constant::BEGIN@28 # spent 8µs making 1 call to strict::unimport
291700ns my $const = $] > 5.009002;
3016µs *_CAN_PCS = sub () {$const};
31
321400ns my $downgrade = $] < 5.015004; # && $] >= 5.008
3318µs *_DOWNGRADE = sub () { $downgrade };
34159µs112µs}
# spent 12µs making 1 call to constant::BEGIN@24
35
36#=======================================================================
37# import() - import symbols into user's namespace
38#
39# What we actually do is define a function in the caller's namespace
40# which returns the value. The function we create will normally
41# be inlined as a constant, thereby avoiding further sub calling
42# overhead.
43#=======================================================================
44
# spent 174µs (135+39) within constant::import which was called 6 times, avg 29µs/call: # once (28µs+8µs) by Data::Dumper::BEGIN@271 at line 271 of Data/Dumper.pm # once (27µs+8µs) by Try::Tiny::ScopeGuard::BEGIN@144 at line 144 of Try/Tiny.pm # once (25µs+6µs) by namespace::clean::BEGIN@146 at line 146 of namespace/clean.pm # once (19µs+8µs) by Eval::Closure::BEGIN@20 at line 20 of Eval/Closure.pm # once (18µs+5µs) by Class::MOP::Method::Meta::BEGIN@16 at line 16 of Class/MOP/Method/Meta.pm # once (17µs+4µs) by namespace::clean::BEGIN@147 at line 147 of namespace/clean.pm
sub import {
4562µs my $class = shift;
4662µs return unless @_; # Ignore 'use constant;'
476200ns my $constants;
4862µs my $multiple = ref $_[0];
4963µs my $pkg = caller;
506200ns my $flush_mro;
516200ns my $symtab;
52
536800ns if (_CAN_PCS) {
542221µs221µs
# spent 13µs (5+8) within constant::BEGIN@54 which was called: # once (5µs+8µs) by Try::Tiny::ScopeGuard::BEGIN@144 at line 54
no strict 'refs';
# spent 13µs making 1 call to constant::BEGIN@54 # spent 8µs making 1 call to strict::unimport
5565µs $symtab = \%{$pkg . '::'};
56 };
57
5861µs if ( $multiple ) {
59 if (ref $_[0] ne 'HASH') {
60 require Carp;
61 Carp::croak("Invalid reference type '".ref(shift)."' not 'HASH'");
62 }
63 $constants = shift;
64 } else {
6561µs unless (defined $_[0]) {
66 require Carp;
67 Carp::croak("Can't use undef as constant name");
68 }
6966µs $constants->{+shift} = undef;
70 }
71
7269µs foreach my $name ( keys %$constants ) {
73 # Normal constant name
74649µs1224µs if ($name =~ $normal_constant_name and !$forbidden{$name}) {
# spent 12µs making 6 calls to constant::CORE:match, avg 2µs/call # spent 12µs making 6 calls to constant::CORE:regcomp, avg 2µs/call
75 # Everything is okay
76
77 # Name forced into main, but we're not in main. Fatal.
78 } elsif ($forced_into_main{$name} and $pkg ne 'main') {
79 require Carp;
80 Carp::croak("Constant name '$name' is forced into main::");
81
82 # Starts with double underscore. Fatal.
83 } elsif ($name =~ /^__/) {
84 require Carp;
85 Carp::croak("Constant name '$name' begins with '__'");
86
87 # Maybe the name is tolerable
88 } elsif ($name =~ $tolerable) {
89 # Then we'll warn only if you've asked for warnings
90 if (warnings::enabled()) {
91 if ($keywords{$name}) {
92 warnings::warn("Constant name '$name' is a Perl keyword");
93 } elsif ($forced_into_main{$name}) {
94 warnings::warn("Constant name '$name' is " .
95 "forced into package main::");
96 }
97 }
98
99 # Looks like a boolean
100 # use constant FRED == fred;
101 } elsif ($name =~ $boolean) {
102 require Carp;
103 if (@_) {
104 Carp::croak("Constant name '$name' is invalid");
105 } else {
106 Carp::croak("Constant name looks like boolean value");
107 }
108
109 } else {
110 # Must have bad characters
111 require Carp;
112 Carp::croak("Constant name '$name' has invalid characters");
113 }
114
115 {
1168216µs222µs
# spent 14µs (6+8) within constant::BEGIN@116 which was called: # once (6µs+8µs) by Try::Tiny::ScopeGuard::BEGIN@144 at line 116
no strict 'refs';
# spent 14µs making 1 call to constant::BEGIN@116 # spent 8µs making 1 call to strict::unimport
11764µs my $full_name = "${pkg}::$name";
11864µs $declared{$full_name}++;
11963µs if ($multiple || @_ == 1) {
12062µs my $scalar = $multiple ? $constants->{$name} : $_[0];
121
122 if (_DOWNGRADE) { # for 5.8 to 5.14
123 # Work around perl bug #31991: Sub names (actually glob
124 # names in general) ignore the UTF8 flag. So we have to
125 # turn it off to get the "right" symbol table entry.
126 utf8::is_utf8 $name and utf8::encode $name;
127 }
128
129 # The constant serves to optimise this entire block out on
130 # 5.8 and earlier.
13163µs if (_CAN_PCS && $symtab && !exists $symtab->{$name}) {
132 # No typeglob yet, so we can use a reference as space-
133 # efficient proxy for a constant subroutine
134 # The check in Perl_ck_rvconst knows that inlinable
135 # constants from cv_const_sv are read only. So we have to:
136620µs68µs Internals::SvREADONLY($scalar, 1);
# spent 8µs making 6 calls to Internals::SvREADONLY, avg 1µs/call
13763µs $symtab->{$name} = \$scalar;
13862µs ++$flush_mro;
139 } else {
140 *$full_name = sub () { $scalar };
141 }
142 } elsif (@_) {
143 my @list = @_;
144 *$full_name = sub () { @list };
145 } else {
146 *$full_name = sub () { };
147 }
148 }
149 }
150 # Flush the cache exactly once if we make any direct symbol table changes.
151640µs67µs mro::method_changed_in($pkg) if _CAN_PCS && $flush_mro;
# spent 7µs making 6 calls to mro::method_changed_in, avg 1µs/call
152}
153
15417µs1;
155
156__END__
 
# spent 12µs within constant::CORE:match which was called 6 times, avg 2µs/call: # 6 times (12µs+0s) by constant::import at line 74, avg 2µs/call
sub constant::CORE:match; # opcode
# spent 3µs within constant::CORE:qr which was called 3 times, avg 933ns/call: # once (2µs+0s) by Try::Tiny::ScopeGuard::BEGIN@144 at line 20 # once (700ns+0s) by Try::Tiny::ScopeGuard::BEGIN@144 at line 21 # once (600ns+0s) by Try::Tiny::ScopeGuard::BEGIN@144 at line 22
sub constant::CORE:qr; # opcode
# spent 12µs within constant::CORE:regcomp which was called 6 times, avg 2µs/call: # 6 times (12µs+0s) by constant::import at line 74, avg 2µs/call
sub constant::CORE:regcomp; # opcode