← 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/lib/perl5/Function/Parameters.pm
StatementsExecuted 319 statements in 4.66ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1114.03ms4.82msFunction::Parameters::::BEGIN@7Function::Parameters::BEGIN@7
1113.28ms3.32msFunction::Parameters::::BEGIN@5Function::Parameters::BEGIN@5
444226µs406µsFunction::Parameters::::importFunction::Parameters::import
121173µs73µsFunction::Parameters::::CORE:regcompFunction::Parameters::CORE:regcomp (opcode)
122155µs144µsFunction::Parameters::::_assert_valid_identifierFunction::Parameters::_assert_valid_identifier
243142µs42µsFunction::Parameters::::CORE:matchFunction::Parameters::CORE:match (opcode)
11121µs21µsFunction::Parameters::::BEGIN@3Function::Parameters::BEGIN@3
11112µs62µsFunction::Parameters::::BEGIN@3.2Function::Parameters::BEGIN@3.2
41111µs27µsFunction::Parameters::::_assert_valid_attributesFunction::Parameters::_assert_valid_attributes
1116µs124µsFunction::Parameters::::BEGIN@10Function::Parameters::BEGIN@10
1114µs4µsFunction::Parameters::::BEGIN@9Function::Parameters::BEGIN@9
0000s0sFunction::Parameters::::unimportFunction::Parameters::unimport
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Function::Parameters;
2
34114µs3134µs
# spent 62µs (12+51) within Function::Parameters::BEGIN@3.2 which was called: # once (12µs+51µs) by main::BEGIN@8 at line 3 # spent 21µs within Function::Parameters::BEGIN@3 which was called: # once (21µs+0s) by main::BEGIN@8 at line 3
use v5.14.0;
# spent 62µs making 1 call to Function::Parameters::BEGIN@3.2 # spent 51µs making 1 call to feature::import # spent 21µs making 1 call to Function::Parameters::BEGIN@3
4
523.11ms23.34ms
# spent 3.32ms (3.28+44µs) within Function::Parameters::BEGIN@5 which was called: # once (3.28ms+44µs) by main::BEGIN@8 at line 5
use warnings;
# spent 3.32ms making 1 call to Function::Parameters::BEGIN@5 # spent 12µs making 1 call to warnings::import
6
72169µs24.96ms
# spent 4.82ms (4.03+789µs) within Function::Parameters::BEGIN@7 which was called: # once (4.03ms+789µs) by main::BEGIN@8 at line 7
use Carp qw(confess);
# spent 4.82ms making 1 call to Function::Parameters::BEGIN@7 # spent 146µs making 1 call to Exporter::import
8
9229µs14µs
# spent 4µs within Function::Parameters::BEGIN@9 which was called: # once (4µs+0s) by main::BEGIN@8 at line 9
use XSLoader;
# spent 4µs making 1 call to Function::Parameters::BEGIN@9
10
# spent 124µs (6+118) within Function::Parameters::BEGIN@10 which was called: # once (6µs+118µs) by main::BEGIN@8 at line 13
BEGIN {
112124µs our $VERSION = '1.0004';
121118µs XSLoader::load;
# spent 118µs making 1 call to XSLoader::load
131679µs1124µs}
# spent 124µs making 1 call to Function::Parameters::BEGIN@10
14
15
# spent 144µs (55+89) within Function::Parameters::_assert_valid_identifier which was called 12 times, avg 12µs/call: # 8 times (40µs+49µs) by Function::Parameters::import at line 90, avg 11µs/call # 4 times (15µs+40µs) by Function::Parameters::import at line 106, avg 14µs/call
sub _assert_valid_identifier {
1636153µs my ($name, $with_dollar) = @_;
17 my $bonus = $with_dollar ? '\$' : '';
182489µs $name =~ /^${bonus}[^\W\d]\w*\z/
# spent 73µs making 12 calls to Function::Parameters::CORE:regcomp, avg 6µs/call # spent 16µs making 12 calls to Function::Parameters::CORE:match, avg 1µs/call
19 or confess qq{"$name" doesn't look like a valid identifier};
20}
21
22
# spent 27µs (11+16) within Function::Parameters::_assert_valid_attributes which was called 4 times, avg 7µs/call: # 4 times (11µs+16µs) by Function::Parameters::import at line 109, avg 7µs/call
sub _assert_valid_attributes {
23829µs my ($attrs) = @_;
24416µs $attrs =~ /^\s*:\s*[^\W\d]\w*\s*(?:(?:\s|:\s*)[^\W\d]\w*\s*)*(?:\(|\z)/
# spent 16µs making 4 calls to Function::Parameters::CORE:match, avg 4µs/call
25 or confess qq{"$attrs" doesn't look like valid attributes};
26}
27
281800nsmy @bare_arms = qw(function method);
2914µsmy %type_map = (
30 function => {
31 name => 'optional',
32 default_arguments => 1,
33 check_argument_count => 0,
34 named_parameters => 1,
35 },
36 method => {
37 name => 'optional',
38 default_arguments => 1,
39 check_argument_count => 0,
40 named_parameters => 1,
41 attrs => ':method',
42 shift => '$self',
43 invocant => 1,
44 },
45 classmethod => {
46 name => 'optional',
47 default_arguments => 1,
48 check_argument_count => 0,
49 named_parameters => 1,
50 attributes => ':method',
51 shift => '$class',
52 invocant => 1,
53 },
54);
5514µsfor my $k (keys %type_map) {
56 $type_map{$k . '_strict'} = {
5738µs %{$type_map{$k}},
58 check_argument_count => 1,
59 };
60}
61
62
# spent 406µs (226+181) within Function::Parameters::import which was called 4 times, avg 102µs/call: # once (66µs+53µs) by main::BEGIN@14 at line 14 of NewIncNPlyPicker.pm # once (59µs+51µs) by main::BEGIN@8 at line 8 of testnewboardincnply # once (53µs+40µs) by NewBoard::BEGIN@18 at line 18 of NewBoard.pm # once (47µs+38µs) by main::BEGIN@6 at line 6 of NewSolveGame.pm
sub import {
633253µs my $class = shift;
64
65 if (!@_) {
66 @_ = {
67 fun => 'function',
68 method => 'method',
69 };
70 }
71 if (@_ == 1 && $_[0] eq ':strict') {
72 @_ = {
73 fun => 'function_strict',
74 method => 'method_strict',
75 };
76 }
77 if (@_ == 1 && ref($_[0]) eq 'HASH') {
78 @_ = map [$_, $_[0]{$_}], keys %{$_[0]};
79 }
80
81 my %spec;
82
83 my $bare = 0;
84 for my $proto (@_) {
85144127µs my $item = ref $proto
86 ? $proto
87 : [$proto, $bare_arms[$bare++] || confess(qq{Don't know what to do with "$proto"})]
88 ;
89 my ($name, $proto_type) = @$item;
90888µs _assert_valid_identifier $name;
# spent 88µs making 8 calls to Function::Parameters::_assert_valid_identifier, avg 11µs/call
91
92 unless (ref $proto_type) {
93 # use '||' instead of 'or' to preserve $proto_type in the error message
94 $proto_type = $type_map{$proto_type}
95 || confess qq["$proto_type" doesn't look like a valid type (one of ${\join ', ', sort keys %type_map})];
96 }
97
98 my %type = %$proto_type;
99 my %clean;
100
101 $clean{name} = delete $type{name} || 'optional';
102810µs $clean{name} =~ /^(?:optional|required|prohibited)\z/
# spent 10µs making 8 calls to Function::Parameters::CORE:match, avg 1µs/call
103 or confess qq["$clean{name}" doesn't look like a valid name attribute (one of optional, required, prohibited)];
104
105 $clean{shift} = delete $type{shift} || '';
106455µs _assert_valid_identifier $clean{shift}, 1 if $clean{shift};
# spent 55µs making 4 calls to Function::Parameters::_assert_valid_identifier, avg 14µs/call
107
108 $clean{attrs} = join ' ', map delete $type{$_} || (), qw(attributes attrs);
109427µs _assert_valid_attributes $clean{attrs} if $clean{attrs};
# spent 27µs making 4 calls to Function::Parameters::_assert_valid_attributes, avg 7µs/call
110
111 $clean{default_arguments} =
112 exists $type{default_arguments}
113 ? !!delete $type{default_arguments}
114 : 1
115 ;
116 $clean{check_argument_count} = !!delete $type{check_argument_count};
117 $clean{invocant} = !!delete $type{invocant};
118 $clean{named_parameters} = !!delete $type{named_parameters};
119
120 %type and confess "Invalid keyword property: @{[keys %type]}";
121
122 $spec{$name} = \%clean;
123 }
124
125 for my $kw (keys %spec) {
1268052µs my $type = $spec{$kw};
127
128 my $flags =
129 $type->{name} eq 'prohibited' ? FLAG_ANON_OK :
130 $type->{name} eq 'required' ? FLAG_NAME_OK :
131 FLAG_ANON_OK | FLAG_NAME_OK
132 ;
133 $flags |= FLAG_DEFAULT_ARGS if $type->{default_arguments};
134 $flags |= FLAG_CHECK_NARGS if $type->{check_argument_count};
135 $flags |= FLAG_INVOCANT if $type->{invocant};
136 $flags |= FLAG_NAMED_PARAMS if $type->{named_parameters};
137 $^H{HINTK_FLAGS_ . $kw} = $flags;
138 $^H{HINTK_SHIFT_ . $kw} = $type->{shift};
139 $^H{HINTK_ATTRS_ . $kw} = $type->{attrs};
140 $^H{+HINTK_KEYWORDS} .= "$kw ";
141 }
142}
143
144sub unimport {
145 my $class = shift;
146
147 if (!@_) {
148 delete $^H{+HINTK_KEYWORDS};
149 return;
150 }
151
152 for my $kw (@_) {
153 $^H{+HINTK_KEYWORDS} =~ s/(?<![^ ])\Q$kw\E //g;
154 }
155}
156
157
15816µs'ok'
159
160__END__
 
# spent 42µs within Function::Parameters::CORE:match which was called 24 times, avg 2µs/call: # 12 times (16µs+0s) by Function::Parameters::_assert_valid_identifier at line 18, avg 1µs/call # 8 times (10µs+0s) by Function::Parameters::import at line 102, avg 1µs/call # 4 times (16µs+0s) by Function::Parameters::_assert_valid_attributes at line 24, avg 4µs/call
sub Function::Parameters::CORE:match; # opcode
# spent 73µs within Function::Parameters::CORE:regcomp which was called 12 times, avg 6µs/call: # 12 times (73µs+0s) by Function::Parameters::_assert_valid_identifier at line 18, avg 6µs/call
sub Function::Parameters::CORE:regcomp; # opcode