← Index
NYTProf Performance Profile   « block view • line view • sub view »
For ./testnewboardincnply
  Run on Mon Jan 12 21:52:27 2015
Reported on Mon Jan 12 22:01:18 2015

Filename/usr/share/perl/5.14/constant.pm
StatementsExecuted 409 statements in 1.05ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
14142242µs316µsconstant::::importconstant::import
204140µs40µsconstant::::CORE:regcompconstant::CORE:regcomp (opcode)
171124µs24µsconstant::::CORE:matchconstant::CORE:match (opcode)
11115µs15µsconstant::::BEGIN@2constant::BEGIN@2
3319µs9µsconstant::::CORE:qrconstant::CORE:qr (opcode)
1117µs7µsconstant::::BEGIN@25constant::BEGIN@25
1116µs9µsconstant::::BEGIN@3constant::BEGIN@3
1115µs12µsconstant::::BEGIN@114constant::BEGIN@114
1114µs12µsconstant::::BEGIN@29constant::BEGIN@29
1114µs11µsconstant::::BEGIN@52constant::BEGIN@52
1114µs23µsconstant::::BEGIN@6constant::BEGIN@6
1114µs48µsconstant::::BEGIN@4constant::BEGIN@4
0000s0sconstant::::__ANON__[:136]constant::__ANON__[:136]
0000s0sconstant::::__ANON__[:140]constant::__ANON__[:140]
0000s0sconstant::::__ANON__[:142]constant::__ANON__[:142]
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;
2234µs115µs
# spent 15µs within constant::BEGIN@2 which was called: # once (15µs+0s) by Getopt::Long::BEGIN@208 at line 2
use 5.005;
# spent 15µs making 1 call to constant::BEGIN@2
3216µs211µs
# spent 9µs (6+2) within constant::BEGIN@3 which was called: # once (6µs+2µs) by Getopt::Long::BEGIN@208 at line 3
use strict;
# spent 9µs making 1 call to constant::BEGIN@3 # spent 2µs making 1 call to strict::import
4219µs292µs
# spent 48µs (4+44) within constant::BEGIN@4 which was called: # once (4µs+44µs) by Getopt::Long::BEGIN@208 at line 4
use warnings::register;
# spent 48µs making 1 call to constant::BEGIN@4 # spent 44µs making 1 call to warnings::register::import
5
6295µs242µs
# spent 23µs (4+19) within constant::BEGIN@6 which was called: # once (4µs+19µs) by Getopt::Long::BEGIN@208 at line 6
use vars qw($VERSION %declared);
# spent 23µs making 1 call to constant::BEGIN@6 # spent 19µs making 1 call to vars::import
71400ns$VERSION = '1.21';
8
9#=======================================================================
10
11# Some names are evil choices.
1214µsmy %keywords = map +($_, 1), qw{ BEGIN INIT CHECK END DESTROY AUTOLOAD };
131900ns$keywords{UNITCHECK}++ if $] > 5.009;
14
15113µ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
201500nsmy $str_end = $] >= 5.006 ? "\\z" : "\\Z";
21130µs217µsmy $normal_constant_name = qr/^_?[^\W_0-9]\w*$str_end/;
# spent 9µs making 1 call to constant::CORE:regcomp # spent 8µs making 1 call to constant::CORE:qr
22116µs212µsmy $tolerable = qr/^[A-Za-z_]\w*$str_end/;
# spent 12µs making 1 call to constant::CORE:regcomp # spent 900ns making 1 call to constant::CORE:qr
2317µs24µsmy $boolean = qr/^[01]?$str_end/;
# spent 3µs making 1 call to constant::CORE:regcomp # spent 800ns making 1 call to constant::CORE:qr
24
25
# spent 7µs within constant::BEGIN@25 which was called: # once (7µs+0s) by Getopt::Long::BEGIN@208 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.
29234µs219µs
# spent 12µs (4+8) within constant::BEGIN@29 which was called: # once (4µs+8µs) by Getopt::Long::BEGIN@208 at line 29
no strict 'refs';
# spent 12µs making 1 call to constant::BEGIN@29 # spent 7µs making 1 call to strict::unimport
30210µs my $const = $] > 5.009002;
31 *_CAN_PCS = sub () {$const};
32152µs17µs}
# spent 7µ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 316µs (242+74) within constant::import which was called 14 times, avg 23µs/call: # once (54µs+18µs) by NewBoard::BEGIN@30 at line 31 of NewBoard.pm # once (23µs+8µs) by Getopt::Long::BEGIN@208 at line 208 of Getopt/Long.pm # once (14µs+9µs) by Getopt::Long::BEGIN@247 at line 247 of Getopt/Long.pm # once (15µs+4µs) by Getopt::Long::BEGIN@218 at line 218 of Getopt/Long.pm # once (14µs+4µs) by Getopt::Long::BEGIN@220 at line 220 of Getopt/Long.pm # once (14µs+4µs) by Getopt::Long::BEGIN@224 at line 224 of Getopt/Long.pm # once (14µs+4µs) by Getopt::Long::BEGIN@226 at line 226 of Getopt/Long.pm # once (14µs+4µs) by Getopt::Long::BEGIN@222 at line 222 of Getopt/Long.pm # once (14µs+4µs) by Getopt::Long::BEGIN@228 at line 228 of Getopt/Long.pm # once (13µs+4µs) by Getopt::Long::BEGIN@237 at line 237 of Getopt/Long.pm # once (14µs+4µs) by Getopt::Long::BEGIN@229 at line 229 of Getopt/Long.pm # once (13µs+4µs) by Getopt::Long::BEGIN@223 at line 223 of Getopt/Long.pm # once (13µs+3µs) by Getopt::Long::BEGIN@236 at line 236 of Getopt/Long.pm # once (13µs+4µs) by Getopt::Long::BEGIN@225 at line 225 of Getopt/Long.pm
sub import {
4315498µs 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
511411µs if (_CAN_PCS) {
522209µs217µs
# spent 11µs (4+7) within constant::BEGIN@52 which was called: # once (4µs+7µs) by Getopt::Long::BEGIN@208 at line 52
no strict 'refs';
# spent 11µs making 1 call to constant::BEGIN@52 # spent 7µs making 1 call to strict::unimport
53 $symtab = \%{$pkg . '::'};
54 };
55
562813µ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
723496µs3440µs if ($name =~ $normal_constant_name and !$forbidden{$name}) {
# spent 24µs making 17 calls to constant::CORE:match, avg 1µs/call # spent 16µs making 17 calls to constant::CORE:regcomp, avg 929ns/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 {
1142170µs219µs
# spent 12µs (5+7) within constant::BEGIN@114 which was called: # once (5µs+7µs) by Getopt::Long::BEGIN@208 at line 114
no strict 'refs';
# spent 12µs making 1 call to constant::BEGIN@114 # spent 7µs making 1 call to strict::unimport
1155126µs my $full_name = "${pkg}::$name";
116 $declared{$full_name}++;
1175146µs if ($multiple || @_ == 1) {
118 my $scalar = $multiple ? $constants->{$name} : $_[0];
119
120 # Work around perl bug #xxxxx: Sub names (actually glob
121 # names in general) ignore the UTF8 flag. So we have to
122 # turn it off to get the "right" symbol table entry.
1231712µs utf8::is_utf8 $name and utf8::encode $name;
# spent 12µs making 17 calls to utf8::is_utf8, avg 700ns/call
124
125 # The constant serves to optimise this entire block out on
126 # 5.8 and earlier.
1275141µs if (_CAN_PCS && $symtab && !exists $symtab->{$name}) {
128 # No typeglob yet, so we can use a reference as space-
129 # efficient proxy for a constant subroutine
130 # The check in Perl_ck_rvconst knows that inlinable
131 # constants from cv_const_sv are read only. So we have to:
132179µs Internals::SvREADONLY($scalar, 1);
# spent 9µs making 17 calls to Internals::SvREADONLY, avg 547ns/call
133 $symtab->{$name} = \$scalar;
134 ++$flush_mro;
135 } else {
136 *$full_name = sub () { $scalar };
137 }
138 } elsif (@_) {
139 my @list = @_;
140 *$full_name = sub () { @list };
141 } else {
142 *$full_name = sub () { };
143 }
144 }
145 }
146 # Flush the cache exactly once if we make any direct symbol table changes.
1471413µs mro::method_changed_in($pkg) if _CAN_PCS && $flush_mro;
# spent 13µs making 14 calls to mro::method_changed_in, avg 929ns/call
148}
149
15017µs1;
151
152__END__
 
# spent 24µs within constant::CORE:match which was called 17 times, avg 1µs/call: # 17 times (24µs+0s) by constant::import at line 72, avg 1µs/call
sub constant::CORE:match; # opcode
# spent 9µs within constant::CORE:qr which was called 3 times, avg 3µs/call: # once (8µs+0s) by Getopt::Long::BEGIN@208 at line 21 # once (900ns+0s) by Getopt::Long::BEGIN@208 at line 22 # once (800ns+0s) by Getopt::Long::BEGIN@208 at line 23
sub constant::CORE:qr; # opcode
# spent 40µs within constant::CORE:regcomp which was called 20 times, avg 2µs/call: # 17 times (16µs+0s) by constant::import at line 72, avg 929ns/call # once (12µs+0s) by Getopt::Long::BEGIN@208 at line 22 # once (9µs+0s) by Getopt::Long::BEGIN@208 at line 21 # once (3µs+0s) by Getopt::Long::BEGIN@208 at line 23
sub constant::CORE:regcomp; # opcode