← Index
NYTProf Performance Profile   « line view »
For /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/bin/perlcritic
  Run on Sat Mar 19 22:12:22 2016
Reported on Sat Mar 19 22:14:11 2016

Filename/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Utils/McCabe.pm
StatementsExecuted 27327 statements in 96.5ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
101611103ms2.54sPerl::Critic::Utils::McCabe::::_count_logic_keywordsPerl::Critic::Utils::McCabe::_count_logic_keywords
10161151.7ms1.42sPerl::Critic::Utils::McCabe::::_count_logic_operatorsPerl::Critic::Utils::McCabe::_count_logic_operators
1016117.34ms3.97sPerl::Critic::Utils::McCabe::::calculate_mccabe_of_subPerl::Critic::Utils::McCabe::calculate_mccabe_of_sub
11117µs17µsPerl::Critic::Utils::McCabe::::BEGIN@10Perl::Critic::Utils::McCabe::BEGIN@10
1118µs13µsPerl::Critic::Utils::McCabe::::BEGIN@18Perl::Critic::Utils::McCabe::BEGIN@18
1117µs27µsPerl::Critic::Utils::McCabe::::BEGIN@14Perl::Critic::Utils::McCabe::BEGIN@14
1117µs339µsPerl::Critic::Utils::McCabe::::BEGIN@16Perl::Critic::Utils::McCabe::BEGIN@16
1116µs10µsPerl::Critic::Utils::McCabe::::BEGIN@12Perl::Critic::Utils::McCabe::BEGIN@12
1116µs18µsPerl::Critic::Utils::McCabe::::BEGIN@11Perl::Critic::Utils::McCabe::BEGIN@11
0000s0sPerl::Critic::Utils::McCabe::::__ANON__[:89]Perl::Critic::Utils::McCabe::__ANON__[:89]
0000s0sPerl::Critic::Utils::McCabe::::_count_main_logic_operators_and_keywordsPerl::Critic::Utils::McCabe::_count_main_logic_operators_and_keywords
0000s0sPerl::Critic::Utils::McCabe::::calculate_mccabe_of_mainPerl::Critic::Utils::McCabe::calculate_mccabe_of_main
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1##############################################################################
2# $URL$
3# $Date$
4# $Author$
5# $Revision$
6##############################################################################
7
8package Perl::Critic::Utils::McCabe;
9
10236µs117µ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
use 5.006001;
# spent 17µs making 1 call to Perl::Critic::Utils::McCabe::BEGIN@10
11218µs229µ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
use strict;
# spent 18µs making 1 call to Perl::Critic::Utils::McCabe::BEGIN@11 # spent 11µs making 1 call to strict::import
12223µs214µ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
use warnings;
# spent 10µs making 1 call to Perl::Critic::Utils::McCabe::BEGIN@12 # spent 4µs making 1 call to warnings::import
13
14222µs247µ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
use Readonly;
# spent 27µs making 1 call to Perl::Critic::Utils::McCabe::BEGIN@14 # spent 20µs making 1 call to Exporter::import
15
16222µs2672µ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
use Perl::Critic::Utils qw{ :data_conversion :classification };
# spent 339µs making 1 call to Perl::Critic::Utils::McCabe::BEGIN@16 # spent 332µs making 1 call to Exporter::import
17
182358µs219µ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
use Exporter 'import';
# 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
221600nsour $VERSION = '1.121';
23
24#-----------------------------------------------------------------------------
25
2612µs125µsReadonly::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
3113µs236µsReadonly::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
3413µs231µsReadonly::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
sub calculate_mccabe_of_sub {
40
411016347µs my ( $sub ) = @_;
42
431016185µs my $count = 1; # Minimum score is 1
4410161.26ms10162.54s $count += _count_logic_keywords( $sub );
# spent 2.54s making 1016 calls to Perl::Critic::Utils::McCabe::_count_logic_keywords, avg 2.50ms/call
4510161.53ms10161.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
4710162.02ms return $count;
48}
49
50#-----------------------------------------------------------------------------
51
52sub 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
63sub _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
sub _count_logic_keywords {
102
1031016174µs my ( $sub ) = @_;
1041016169µ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
11010161.39ms10161.35s my $keywords_ref = $sub->find('PPI::Token::Word');
# spent 1.35s making 1016 calls to PPI::Node::find, avg 1.33ms/call
1111016366µs if ( $keywords_ref ) { # should always be true due to "sub" keyword
1121105417.1ms100381.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
113101636.2ms1870663.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 }
11510162.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
sub _count_logic_operators {
121
1221016330µs my ( $sub ) = @_;
1231016194µ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
12910161.54ms10161.33s my $operators_ref = $sub->find('PPI::Token::Operator');
# spent 1.33s making 1016 calls to PPI::Node::find, avg 1.31ms/call
130101628.0ms1470844.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
13410162.53ms return $count;
135}
136
137
13816µs1;
139
140__END__