← Index
NYTProf Performance Profile   « block view • line view • sub view »
For mongo_pain.pl
  Run on Fri Mar 25 17:00:29 2011
Reported on Fri Mar 25 17:07:06 2011

Filename/usr/share/perl/5.10/constant.pm
StatementsExecuted 455 statements in 1.83ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
19194574µs746µsconstant::::importconstant::import
11157µs57µsconstant::::BEGIN@2constant::BEGIN@2
191154µs54µsconstant::::CORE:matchconstant::CORE:match (opcode)
191134µs34µsconstant::::CORE:regcompconstant::CORE:regcomp (opcode)
1119µs24µsconstant::::BEGIN@38constant::BEGIN@38
1119µs12µsconstant::::BEGIN@3constant::BEGIN@3
1119µs22µsconstant::::BEGIN@101constant::BEGIN@101
1119µs83µsconstant::::BEGIN@4constant::BEGIN@4
1118µs48µsconstant::::BEGIN@6constant::BEGIN@6
0000s0sconstant::::__ANON__[:115]constant::__ANON__[:115]
0000s0sconstant::::__ANON__[:119]constant::__ANON__[:119]
0000s0sconstant::::__ANON__[:121]constant::__ANON__[:121]
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package constant;
2377µs157µs
# spent 57µs within constant::BEGIN@2 which was called: # once (57µs+0s) by DateTime::Duration::BEGIN@23 at line 2
use 5.005;
# spent 57µs making 1 call to constant::BEGIN@2
3330µs216µs
# spent 12µs (9+3) within constant::BEGIN@3 which was called: # once (9µs+3µs) by DateTime::Duration::BEGIN@23 at line 3
use strict;
# spent 12µs making 1 call to constant::BEGIN@3 # spent 3µs making 1 call to strict::import
4336µs2158µs
# spent 83µs (9+75) within constant::BEGIN@4 which was called: # once (9µs+75µs) by DateTime::Duration::BEGIN@23 at line 4
use warnings::register;
# spent 83µs making 1 call to constant::BEGIN@4 # spent 75µs making 1 call to warnings::register::import
5
63180µs287µs
# spent 48µs (8+40) within constant::BEGIN@6 which was called: # once (8µs+40µs) by DateTime::Duration::BEGIN@23 at line 6
use vars qw($VERSION %declared);
# spent 48µs making 1 call to constant::BEGIN@6 # spent 40µs making 1 call to vars::import
71800ns$VERSION = '1.17';
8
9#=======================================================================
10
11# Some names are evil choices.
1216µsmy %keywords = map +($_, 1), qw{ BEGIN INIT CHECK END DESTROY AUTOLOAD };
1311µ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
1816µsmy %forbidden = (%keywords, %forced_into_main);
19
20#=======================================================================
21# import() - import symbols into user's namespace
22#
23# What we actually do is define a function in the caller's namespace
24# which returns the value. The function we create will normally
25# be inlined as a constant, thereby avoiding further sub calling
26# overhead.
27#=======================================================================
28
# spent 746µs (574+173) within constant::import which was called 19 times, avg 39µs/call: # once (48µs+27µs) by DateTime::Duration::BEGIN@23 at line 23 of DateTime/Duration.pm # once (44µs+14µs) by DateTime::TimeZone::BEGIN@18 at line 18 of DateTime/TimeZone.pm # once (28µs+16µs) by DateTime::TimeZone::BEGIN@23 at line 23 of DateTime/TimeZone.pm # once (34µs+9µs) by DateTime::TimeZone::BEGIN@25 at line 25 of DateTime/TimeZone.pm # once (29µs+9µs) by DateTime::TimeZone::BEGIN@19 at line 19 of DateTime/TimeZone.pm # once (28µs+9µs) by DateTime::TimeZone::BEGIN@26 at line 26 of DateTime/TimeZone.pm # once (27µs+9µs) by DateTime::TimeZone::BEGIN@22 at line 22 of DateTime/TimeZone.pm # once (33µs+4µs) by DateTime::BEGIN@74 at line 74 of DateTime.pm # once (29µs+8µs) by Time::Local::BEGIN@28 at line 28 of Time/Local.pm # once (27µs+9µs) by DateTime::TimeZone::BEGIN@28 at line 28 of DateTime/TimeZone.pm # once (27µs+9µs) by DateTime::TimeZone::BEGIN@24 at line 24 of DateTime/TimeZone.pm # once (27µs+9µs) by DateTime::TimeZone::BEGIN@27 at line 27 of DateTime/TimeZone.pm # once (28µs+7µs) by DateTime::BEGIN@72 at line 72 of DateTime.pm # once (27µs+7µs) by Time::Local::BEGIN@30 at line 30 of Time/Local.pm # once (27µs+7µs) by DateTime::BEGIN@78 at line 78 of DateTime.pm # once (27µs+6µs) by Time::Local::BEGIN@29 at line 29 of Time/Local.pm # once (30µs+3µs) by DateTime::BEGIN@75 at line 75 of DateTime.pm # once (26µs+6µs) by DateTime::BEGIN@80 at line 80 of DateTime.pm # once (28µs+4µs) by DateTime::BEGIN@76 at line 76 of DateTime.pm
sub import {
29431797µs my $class = shift;
30 return unless @_; # Ignore 'use constant;'
31 my $constants;
32 my $multiple = ref $_[0];
33 my $pkg = caller;
34 my $symtab;
35 my $str_end = $] >= 5.006 ? "\\z" : "\\Z";
36
37 if ($] > 5.009002) {
383393µs239µs
# spent 24µs (9+15) within constant::BEGIN@38 which was called: # once (9µs+15µs) by DateTime::Duration::BEGIN@23 at line 38
no strict 'refs';
# spent 24µs making 1 call to constant::BEGIN@38 # spent 15µs making 1 call to strict::unimport
39 $symtab = \%{$pkg . '::'};
40 };
41
42 if ( $multiple ) {
43 if (ref $_[0] ne 'HASH') {
44 require Carp;
45 Carp::croak("Invalid reference type '".ref(shift)."' not 'HASH'");
46 }
47 $constants = shift;
48 } else {
49 $constants->{+shift} = undef;
50 }
51
52 foreach my $name ( keys %$constants ) {
53 unless (defined $name) {
54 require Carp;
55 Carp::croak("Can't use undef as constant name");
56 }
57
58 # Normal constant name
593888µs if ($name =~ /^_?[^\W_0-9]\w*$str_end/ and !$forbidden{$name}) {
# spent 54µs making 19 calls to constant::CORE:match, avg 3µs/call # spent 34µs making 19 calls to constant::CORE:regcomp, avg 2µs/call
60 # Everything is okay
61
62 # Name forced into main, but we're not in main. Fatal.
63 } elsif ($forced_into_main{$name} and $pkg ne 'main') {
64 require Carp;
65 Carp::croak("Constant name '$name' is forced into main::");
66
67 # Starts with double underscore. Fatal.
68 } elsif ($name =~ /^__/) {
69 require Carp;
70 Carp::croak("Constant name '$name' begins with '__'");
71
72 # Maybe the name is tolerable
73 } elsif ($name =~ /^[A-Za-z_]\w*$str_end/) {
74 # Then we'll warn only if you've asked for warnings
75 if (warnings::enabled()) {
76 if ($keywords{$name}) {
77 warnings::warn("Constant name '$name' is a Perl keyword");
78 } elsif ($forced_into_main{$name}) {
79 warnings::warn("Constant name '$name' is " .
80 "forced into package main::");
81 }
82 }
83
84 # Looks like a boolean
85 # use constant FRED == fred;
86 } elsif ($name =~ /^[01]?$str_end/) {
87 require Carp;
88 if (@_) {
89 Carp::croak("Constant name '$name' is invalid");
90 } else {
91 Carp::croak("Constant name looks like boolean value");
92 }
93
94 } else {
95 # Must have bad characters
96 require Carp;
97 Carp::croak("Constant name '$name' has invalid characters");
98 }
99
100 {
1013286µs235µs
# spent 22µs (9+13) within constant::BEGIN@101 which was called: # once (9µs+13µs) by DateTime::Duration::BEGIN@23 at line 101
no strict 'refs';
# spent 22µs making 1 call to constant::BEGIN@101 # spent 13µs making 1 call to strict::unimport
102 my $full_name = "${pkg}::$name";
103 $declared{$full_name}++;
104 if ($multiple || @_ == 1) {
105 my $scalar = $multiple ? $constants->{$name} : $_[0];
106 if ($symtab && !exists $symtab->{$name}) {
107 # No typeglob yet, so we can use a reference as space-
108 # efficient proxy for a constant subroutine
109 # The check in Perl_ck_rvconst knows that inlinable
110 # constants from cv_const_sv are read only. So we have to:
1111631µs Internals::SvREADONLY($scalar, 1);
# spent 31µs making 16 calls to Internals::SvREADONLY, avg 2µs/call
112 $symtab->{$name} = \$scalar;
1131654µs mro::method_changed_in($pkg);
# spent 54µs making 16 calls to mro::method_changed_in, avg 3µs/call
114 } else {
115 *$full_name = sub () { $scalar };
116 }
117 } elsif (@_) {
118 my @list = @_;
119 *$full_name = sub () { @list };
120 } else {
121 *$full_name = sub () { };
122 }
123 }
124 }
125}
126
127110µs1;
128
129__END__
 
# spent 54µs within constant::CORE:match which was called 19 times, avg 3µs/call: # 19 times (54µs+0s) by constant::import at line 59, avg 3µs/call
sub constant::CORE:match; # opcode
# spent 34µs within constant::CORE:regcomp which was called 19 times, avg 2µs/call: # 19 times (34µs+0s) by constant::import at line 59, avg 2µs/call
sub constant::CORE:regcomp; # opcode