Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Utils/McCabe.pm |
Statements | Executed 27327 statements in 96.5ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1016 | 1 | 1 | 103ms | 2.54s | _count_logic_keywords | Perl::Critic::Utils::McCabe::
1016 | 1 | 1 | 51.7ms | 1.42s | _count_logic_operators | Perl::Critic::Utils::McCabe::
1016 | 1 | 1 | 7.34ms | 3.97s | calculate_mccabe_of_sub | Perl::Critic::Utils::McCabe::
1 | 1 | 1 | 17µs | 17µs | BEGIN@10 | Perl::Critic::Utils::McCabe::
1 | 1 | 1 | 8µs | 13µs | BEGIN@18 | Perl::Critic::Utils::McCabe::
1 | 1 | 1 | 7µs | 27µs | BEGIN@14 | Perl::Critic::Utils::McCabe::
1 | 1 | 1 | 7µs | 339µs | BEGIN@16 | Perl::Critic::Utils::McCabe::
1 | 1 | 1 | 6µs | 10µs | BEGIN@12 | Perl::Critic::Utils::McCabe::
1 | 1 | 1 | 6µs | 18µs | BEGIN@11 | Perl::Critic::Utils::McCabe::
0 | 0 | 0 | 0s | 0s | __ANON__[:89] | Perl::Critic::Utils::McCabe::
0 | 0 | 0 | 0s | 0s | _count_main_logic_operators_and_keywords | Perl::Critic::Utils::McCabe::
0 | 0 | 0 | 0s | 0s | calculate_mccabe_of_main | Perl::Critic::Utils::McCabe::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | ############################################################################## | ||||
2 | # $URL$ | ||||
3 | # $Date$ | ||||
4 | # $Author$ | ||||
5 | # $Revision$ | ||||
6 | ############################################################################## | ||||
7 | |||||
8 | package Perl::Critic::Utils::McCabe; | ||||
9 | |||||
10 | 2 | 36µs | 1 | 17µs | # spent 17µs within Perl::Critic::Utils::McCabe::BEGIN@10 which was called:
# once (17µs+0s) by Perl::Critic::Policy::Subroutines::ProhibitExcessComplexity::BEGIN@16 at line 10 # spent 17µs making 1 call to Perl::Critic::Utils::McCabe::BEGIN@10 |
11 | 2 | 18µs | 2 | 29µs | # spent 18µs (6+11) within Perl::Critic::Utils::McCabe::BEGIN@11 which was called:
# once (6µs+11µs) by Perl::Critic::Policy::Subroutines::ProhibitExcessComplexity::BEGIN@16 at line 11 # spent 18µs making 1 call to Perl::Critic::Utils::McCabe::BEGIN@11
# spent 11µs making 1 call to strict::import |
12 | 2 | 23µs | 2 | 14µs | # spent 10µs (6+4) within Perl::Critic::Utils::McCabe::BEGIN@12 which was called:
# once (6µs+4µs) by Perl::Critic::Policy::Subroutines::ProhibitExcessComplexity::BEGIN@16 at line 12 # spent 10µs making 1 call to Perl::Critic::Utils::McCabe::BEGIN@12
# spent 4µs making 1 call to warnings::import |
13 | |||||
14 | 2 | 22µs | 2 | 47µs | # spent 27µs (7+20) within Perl::Critic::Utils::McCabe::BEGIN@14 which was called:
# once (7µs+20µs) by Perl::Critic::Policy::Subroutines::ProhibitExcessComplexity::BEGIN@16 at line 14 # spent 27µs making 1 call to Perl::Critic::Utils::McCabe::BEGIN@14
# spent 20µs making 1 call to Exporter::import |
15 | |||||
16 | 2 | 22µs | 2 | 672µs | # spent 339µs (7+332) within Perl::Critic::Utils::McCabe::BEGIN@16 which was called:
# once (7µs+332µs) by Perl::Critic::Policy::Subroutines::ProhibitExcessComplexity::BEGIN@16 at line 16 # spent 339µs making 1 call to Perl::Critic::Utils::McCabe::BEGIN@16
# spent 332µs making 1 call to Exporter::import |
17 | |||||
18 | 2 | 358µs | 2 | 19µs | # spent 13µs (8+6) within Perl::Critic::Utils::McCabe::BEGIN@18 which was called:
# once (8µs+6µs) by Perl::Critic::Policy::Subroutines::ProhibitExcessComplexity::BEGIN@16 at line 18 # spent 13µs making 1 call to Perl::Critic::Utils::McCabe::BEGIN@18
# spent 6µs making 1 call to Exporter::import |
19 | |||||
20 | #----------------------------------------------------------------------------- | ||||
21 | |||||
22 | 1 | 600ns | our $VERSION = '1.121'; | ||
23 | |||||
24 | #----------------------------------------------------------------------------- | ||||
25 | |||||
26 | 1 | 2µs | 1 | 25µs | Readonly::Array our @EXPORT_OK => # spent 25µs making 1 call to Readonly::Array |
27 | qw( calculate_mccabe_of_sub calculate_mccabe_of_main ); | ||||
28 | |||||
29 | #----------------------------------------------------------------------------- | ||||
30 | |||||
31 | 1 | 3µs | 2 | 36µs | Readonly::Hash my %LOGIC_OPS => # spent 32µs making 1 call to Readonly::Hash
# spent 4µs making 1 call to Perl::Critic::Utils::hashify |
32 | hashify( qw( && || ||= &&= or and xor ? <<= >>= ) ); | ||||
33 | |||||
34 | 1 | 3µs | 2 | 31µs | Readonly::Hash my %LOGIC_KEYWORDS => # spent 27µs making 1 call to Readonly::Hash
# spent 3µs making 1 call to Perl::Critic::Utils::hashify |
35 | hashify( qw( if else elsif unless until while for foreach ) ); | ||||
36 | |||||
37 | #----------------------------------------------------------------------------- | ||||
38 | |||||
39 | # spent 3.97s (7.34ms+3.96) within Perl::Critic::Utils::McCabe::calculate_mccabe_of_sub which was called 1016 times, avg 3.91ms/call:
# 1016 times (7.34ms+3.96s) by Perl::Critic::Statistics::accumulate at line 56 of Perl/Critic/Statistics.pm, avg 3.91ms/call | ||||
40 | |||||
41 | 1016 | 347µs | my ( $sub ) = @_; | ||
42 | |||||
43 | 1016 | 185µs | my $count = 1; # Minimum score is 1 | ||
44 | 1016 | 1.26ms | 1016 | 2.54s | $count += _count_logic_keywords( $sub ); # spent 2.54s making 1016 calls to Perl::Critic::Utils::McCabe::_count_logic_keywords, avg 2.50ms/call |
45 | 1016 | 1.53ms | 1016 | 1.42s | $count += _count_logic_operators( $sub ); # spent 1.42s making 1016 calls to Perl::Critic::Utils::McCabe::_count_logic_operators, avg 1.40ms/call |
46 | |||||
47 | 1016 | 2.02ms | return $count; | ||
48 | } | ||||
49 | |||||
50 | #----------------------------------------------------------------------------- | ||||
51 | |||||
52 | sub calculate_mccabe_of_main { | ||||
53 | |||||
54 | my ( $doc ) = @_; | ||||
55 | |||||
56 | my $count = 1; # Minimum score is 1 | ||||
57 | $count += _count_main_logic_operators_and_keywords( $doc ); | ||||
58 | return $count; | ||||
59 | } | ||||
60 | |||||
61 | #----------------------------------------------------------------------------- | ||||
62 | |||||
63 | sub _count_main_logic_operators_and_keywords { | ||||
64 | |||||
65 | my ( $doc ) = @_; | ||||
66 | |||||
67 | # I can't leverage Perl::Critic::Document's fast search mechanism here | ||||
68 | # because we're not searching for elements by class name. So to speed | ||||
69 | # things up, search for both keywords and operators at the same time. | ||||
70 | |||||
71 | my $wanted = sub { | ||||
72 | |||||
73 | my (undef, $elem) = @_; | ||||
74 | |||||
75 | # Only count things that *are not* in a subroutine. Returning an | ||||
76 | # explicit 'undef' here prevents PPI from descending into the node. | ||||
77 | |||||
78 | ## no critic (ProhibitExplicitReturnUndef) | ||||
79 | return undef if $elem->isa('PPI::Statement::Sub'); | ||||
80 | |||||
81 | |||||
82 | if ( $elem->isa('PPI::Token::Word') ) { | ||||
83 | return 0 if is_hash_key( $elem ); | ||||
84 | return exists $LOGIC_KEYWORDS{$elem}; | ||||
85 | } | ||||
86 | elsif ($elem->isa('PPI::Token::Operator') ) { | ||||
87 | return exists $LOGIC_OPS{$elem}; | ||||
88 | } | ||||
89 | }; | ||||
90 | |||||
91 | my $logic_operators_and_keywords = $doc->find( $wanted ); | ||||
92 | |||||
93 | my $count = $logic_operators_and_keywords ? | ||||
94 | scalar @{$logic_operators_and_keywords} : 0; | ||||
95 | |||||
96 | return $count; | ||||
97 | } | ||||
98 | |||||
99 | #----------------------------------------------------------------------------- | ||||
100 | |||||
101 | # spent 2.54s (103ms+2.44) within Perl::Critic::Utils::McCabe::_count_logic_keywords which was called 1016 times, avg 2.50ms/call:
# 1016 times (103ms+2.44s) by Perl::Critic::Utils::McCabe::calculate_mccabe_of_sub at line 44, avg 2.50ms/call | ||||
102 | |||||
103 | 1016 | 174µs | my ( $sub ) = @_; | ||
104 | 1016 | 169µs | my $count = 0; | ||
105 | |||||
106 | # Here, I'm using this round-about method of finding elements so | ||||
107 | # that I can take advantage of Perl::Critic::Document's faster | ||||
108 | # find() mechanism. It can only search for elements by class name. | ||||
109 | |||||
110 | 1016 | 1.39ms | 1016 | 1.35s | my $keywords_ref = $sub->find('PPI::Token::Word'); # spent 1.35s making 1016 calls to PPI::Node::find, avg 1.33ms/call |
111 | 1016 | 366µs | if ( $keywords_ref ) { # should always be true due to "sub" keyword | ||
112 | 11054 | 17.1ms | 10038 | 1.02s | my @filtered = grep { ! is_hash_key($_) } @{ $keywords_ref }; # spent 1.02s making 10038 calls to Perl::Critic::Utils::is_hash_key, avg 102µs/call |
113 | 1016 | 36.2ms | 18706 | 63.1ms | $count = grep { exists $LOGIC_KEYWORDS{$_} } @filtered; # spent 49.2ms making 9353 calls to Readonly::Hash::EXISTS, avg 5µs/call
# spent 13.9ms making 9353 calls to PPI::Token::content, avg 1µs/call |
114 | } | ||||
115 | 1016 | 2.70ms | return $count; | ||
116 | } | ||||
117 | |||||
118 | #----------------------------------------------------------------------------- | ||||
119 | |||||
120 | # spent 1.42s (51.7ms+1.37) within Perl::Critic::Utils::McCabe::_count_logic_operators which was called 1016 times, avg 1.40ms/call:
# 1016 times (51.7ms+1.37s) by Perl::Critic::Utils::McCabe::calculate_mccabe_of_sub at line 45, avg 1.40ms/call | ||||
121 | |||||
122 | 1016 | 330µs | my ( $sub ) = @_; | ||
123 | 1016 | 194µs | my $count = 0; | ||
124 | |||||
125 | # Here, I'm using this round-about method of finding elements so | ||||
126 | # that I can take advantage of Perl::Critic::Document's faster | ||||
127 | # find() mechanism. It can only search for elements by class name. | ||||
128 | |||||
129 | 1016 | 1.54ms | 1016 | 1.33s | my $operators_ref = $sub->find('PPI::Token::Operator'); # spent 1.33s making 1016 calls to PPI::Node::find, avg 1.31ms/call |
130 | 1016 | 28.0ms | 14708 | 44.9ms | if ( $operators_ref ) { # spent 33.9ms making 7354 calls to Readonly::Hash::EXISTS, avg 5µs/call
# spent 11.0ms making 7354 calls to PPI::Token::content, avg 1µs/call |
131 | $count = grep { exists $LOGIC_OPS{$_} } @{ $operators_ref }; | ||||
132 | } | ||||
133 | |||||
134 | 1016 | 2.53ms | return $count; | ||
135 | } | ||||
136 | |||||
137 | |||||
138 | 1 | 6µs | 1; | ||
139 | |||||
140 | __END__ |