Filename | /home/ss5/perl5/perlbrew/perls/tapper-perl/lib/site_perl/5.16.3/Data/DPath/Context.pm |
Statements | Executed 973 statements in 4.69ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 2.38ms | 5.71ms | BEGIN@22 | Data::DPath::Context::
1 | 1 | 1 | 1.65ms | 10.1ms | BEGIN@23 | Data::DPath::Context::
1 | 1 | 1 | 1.08ms | 9.60ms | BEGIN@19 | Data::DPath::Context::
8 | 2 | 1 | 543µs | 591µs | _any (recurses: max depth 7, inclusive time 2.03ms) | Data::DPath::Context::
1 | 1 | 1 | 459µs | 664µs | BEGIN@18 | Data::DPath::Context::
11 | 1 | 1 | 362µs | 425µs | _select_key | Data::DPath::Context::
1 | 1 | 1 | 344µs | 721µs | BEGIN@16 | Data::DPath::Context::
6 | 3 | 2 | 231µs | 1.59ms | _search | Data::DPath::Context::
1 | 1 | 1 | 224µs | 288µs | BEGIN@17 | Data::DPath::Context::
29 | 5 | 1 | 117µs | 146µs | _filter_points | Data::DPath::Context::
2 | 1 | 1 | 101µs | 184µs | _select_anystep | Data::DPath::Context::
13 | 1 | 1 | 75µs | 79µs | __ANON__[:411] | Data::DPath::Context::
4 | 2 | 2 | 49µs | 1.61ms | _iter | Data::DPath::Context::
3 | 2 | 1 | 45µs | 1.92ms | isearch | Data::DPath::Context::
6 | 1 | 1 | 43µs | 65µs | _select_root | Data::DPath::Context::
2 | 1 | 1 | 40µs | 46µs | _select_ancestor | Data::DPath::Context::
1 | 1 | 1 | 34µs | 631µs | _select_anywhere | Data::DPath::Context::
2 | 1 | 1 | 34µs | 54µs | _all | Data::DPath::Context::
3 | 3 | 3 | 28µs | 28µs | new (xsub) | Data::DPath::Context::
10 | 1 | 1 | 28µs | 29µs | first_point | Data::DPath::Context::
1 | 1 | 1 | 19µs | 225µs | BEGIN@64 | Data::DPath::Context::
2 | 1 | 1 | 19µs | 572µs | match | Data::DPath::Context::
1 | 1 | 1 | 17µs | 680µs | BEGIN@29 | Data::DPath::Context::
1 | 1 | 1 | 16µs | 34µs | BEGIN@102 | Data::DPath::Context::
1 | 1 | 1 | 15µs | 184µs | BEGIN@57 | Data::DPath::Context::
8 | 8 | 3 | 14µs | 14µs | current_points (xsub) | Data::DPath::Context::
1 | 1 | 1 | 14µs | 32µs | BEGIN@158 | Data::DPath::Context::
1 | 1 | 1 | 13µs | 36µs | BEGIN@204 | Data::DPath::Filters::
1 | 1 | 1 | 12µs | 24µs | BEGIN@159 | Data::DPath::Context::
1 | 1 | 1 | 12µs | 41µs | BEGIN@20 | Data::DPath::Context::
1 | 1 | 1 | 10µs | 16µs | BEGIN@425 | Data::DPath::Context::
1 | 1 | 1 | 9µs | 12µs | BEGIN@11 | Data::DPath::Context::
2 | 1 | 1 | 9µs | 9µs | _filter_points_index | Data::DPath::Context::
1 | 1 | 1 | 9µs | 16µs | BEGIN@281 | Data::DPath::Context::
1 | 1 | 1 | 8µs | 15µs | BEGIN@305 | Data::DPath::Context::
2 | 1 | 1 | 8µs | 8µs | CORE:subst (opcode) | Data::DPath::Context::
1 | 1 | 1 | 8µs | 15µs | BEGIN@223 | Data::DPath::Context::
1 | 1 | 1 | 8µs | 17µs | BEGIN@222 | Data::DPath::Context::
1 | 1 | 1 | 7µs | 27µs | BEGIN@13 | Data::DPath::Context::
1 | 1 | 1 | 7µs | 17µs | BEGIN@424 | Data::DPath::Context::
1 | 1 | 1 | 6µs | 70µs | BEGIN@14 | Data::DPath::Context::
1 | 1 | 1 | 6µs | 6µs | BEGIN@2 | Data::DPath::Context::
1 | 1 | 1 | 6µs | 310µs | BEGIN@15 | Data::DPath::Context::
1 | 1 | 1 | 6µs | 16µs | BEGIN@10 | Data::DPath::Context::
2 | 1 | 1 | 5µs | 5µs | CORE:match (opcode) | Data::DPath::Context::
4 | 1 | 1 | 4µs | 4µs | CORE:substcont (opcode) | Data::DPath::Context::
1 | 1 | 1 | 4µs | 4µs | BEGIN@33 | Data::DPath::Filters::
2 | 2 | 2 | 2µs | 2µs | give_references (xsub) | Data::DPath::Context::
0 | 0 | 0 | 0s | 0s | _filter_points_eval | Data::DPath::Context::
0 | 0 | 0 | 0s | 0s | _select_ancestor_or_self | Data::DPath::Context::
0 | 0 | 0 | 0s | 0s | _select_nostep | Data::DPath::Context::
0 | 0 | 0 | 0s | 0s | _select_parent | Data::DPath::Context::
0 | 0 | 0 | 0s | 0s | _splice_threads | Data::DPath::Context::
0 | 0 | 0 | 0s | 0s | all_points | Data::DPath::Context::
0 | 0 | 0 | 0s | 0s | deref | Data::DPath::Context::
0 | 0 | 0 | 0s | 0s | ref | Data::DPath::Context::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Data::DPath::Context; | ||||
2 | # spent 6µs within Data::DPath::Context::BEGIN@2 which was called:
# once (6µs+0s) by Data::DPath::Path::BEGIN@1.2 at line 4 | ||||
3 | 1 | 5µs | $Data::DPath::Context::AUTHORITY = 'cpan:SCHWIGON'; | ||
4 | 1 | 20µs | 1 | 6µs | } # spent 6µs making 1 call to Data::DPath::Context::BEGIN@2 |
5 | { | ||||
6 | 2 | 900ns | $Data::DPath::Context::VERSION = '0.49'; | ||
7 | } | ||||
8 | # ABSTRACT: Abstraction for a current context that enables incremental searches | ||||
9 | |||||
10 | 2 | 16µs | 2 | 25µs | # spent 16µs (6+10) within Data::DPath::Context::BEGIN@10 which was called:
# once (6µs+10µs) by Data::DPath::Path::BEGIN@1.2 at line 10 # spent 16µs making 1 call to Data::DPath::Context::BEGIN@10
# spent 10µs making 1 call to strict::import |
11 | 2 | 32µs | 2 | 15µs | # spent 12µs (9+3) within Data::DPath::Context::BEGIN@11 which was called:
# once (9µs+3µs) by Data::DPath::Path::BEGIN@1.2 at line 11 # spent 12µs making 1 call to Data::DPath::Context::BEGIN@11
# spent 3µs making 1 call to warnings::import |
12 | |||||
13 | 2 | 19µs | 2 | 46µs | # spent 27µs (7+19) within Data::DPath::Context::BEGIN@13 which was called:
# once (7µs+19µs) by Data::DPath::Path::BEGIN@1.2 at line 13 # spent 27µs making 1 call to Data::DPath::Context::BEGIN@13
# spent 19µs making 1 call to Exporter::import |
14 | 2 | 20µs | 2 | 70µs | # spent 70µs (6+63) within Data::DPath::Context::BEGIN@14 which was called:
# once (6µs+63µs) by Data::DPath::Path::BEGIN@1.2 at line 14 # spent 70µs making 1 call to Data::DPath::Context::BEGIN@14
# spent 63µs making 1 call to aliased::import, recursion: max depth 1, sum of overlapping time 63µs |
15 | 2 | 20µs | 2 | 310µs | # spent 310µs (6+304) within Data::DPath::Context::BEGIN@15 which was called:
# once (6µs+304µs) by Data::DPath::Path::BEGIN@1.2 at line 15 # spent 310µs making 1 call to Data::DPath::Context::BEGIN@15
# spent 304µs making 1 call to aliased::import, recursion: max depth 1, sum of overlapping time 304µs |
16 | 2 | 72µs | 2 | 790µs | # spent 721µs (344+377) within Data::DPath::Context::BEGIN@16 which was called:
# once (344µs+377µs) by Data::DPath::Path::BEGIN@1.2 at line 16 # spent 721µs making 1 call to Data::DPath::Context::BEGIN@16
# spent 69µs making 1 call to Exporter::import |
17 | 2 | 69µs | 2 | 332µs | # spent 288µs (224+63) within Data::DPath::Context::BEGIN@17 which was called:
# once (224µs+63µs) by Data::DPath::Path::BEGIN@1.2 at line 17 # spent 288µs making 1 call to Data::DPath::Context::BEGIN@17
# spent 44µs making 1 call to Exporter::import |
18 | 2 | 77µs | 1 | 664µs | # spent 664µs (459+205) within Data::DPath::Context::BEGIN@18 which was called:
# once (459µs+205µs) by Data::DPath::Path::BEGIN@1.2 at line 18 # spent 664µs making 1 call to Data::DPath::Context::BEGIN@18 |
19 | 2 | 76µs | 2 | 9.65ms | # spent 9.60ms (1.08+8.52) within Data::DPath::Context::BEGIN@19 which was called:
# once (1.08ms+8.52ms) by Data::DPath::Path::BEGIN@1.2 at line 19 # spent 9.60ms making 1 call to Data::DPath::Context::BEGIN@19
# spent 55µs making 1 call to Exporter::import |
20 | 2 | 21µs | 2 | 49µs | # spent 41µs (12+29) within Data::DPath::Context::BEGIN@20 which was called:
# once (12µs+29µs) by Data::DPath::Path::BEGIN@1.2 at line 20 # spent 41µs making 1 call to Data::DPath::Context::BEGIN@20
# spent 8µs making 1 call to List::Util::import |
21 | #use Sys::CPU; | ||||
22 | 2 | 77µs | 2 | 8.33ms | # spent 5.71ms (2.38+3.33) within Data::DPath::Context::BEGIN@22 which was called:
# once (2.38ms+3.33ms) by Data::DPath::Path::BEGIN@1.2 at line 22 # spent 5.71ms making 1 call to Data::DPath::Context::BEGIN@22
# spent 2.63ms making 1 call to POSIX::import |
23 | 2 | 109µs | 1 | 10.1ms | # spent 10.1ms (1.65+8.45) within Data::DPath::Context::BEGIN@23 which was called:
# once (1.65ms+8.45ms) by Data::DPath::Path::BEGIN@1.2 at line 23 # spent 10.1ms making 1 call to Data::DPath::Context::BEGIN@23 |
24 | |||||
25 | # run filter expressions in own Safe.pm compartment | ||||
26 | 1 | 200ns | our $COMPARTMENT; | ||
27 | 1 | 100ns | our $THREADCOUNT; | ||
28 | |||||
29 | # spent 680µs (17+663) within Data::DPath::Context::BEGIN@29 which was called:
# once (17µs+663µs) by Data::DPath::Path::BEGIN@1.2 at line 51 | ||||
30 | #$THREADCOUNT = $Data::DPath::PARALLELIZE ? Sys::CPU::cpu_count : 1; | ||||
31 | #print "THREADCOUNT: $THREADCOUNT\n"; | ||||
32 | package Data::DPath::Filters; | ||||
33 | # spent 4µs within Data::DPath::Filters::BEGIN@33 which was called:
# once (4µs+0s) by Data::DPath::Path::BEGIN@1.2 at line 35 | ||||
34 | 1 | 4µs | $Data::DPath::Filters::AUTHORITY = 'cpan:SCHWIGON'; | ||
35 | 1 | 43µs | 1 | 4µs | } # spent 4µs making 1 call to Data::DPath::Filters::BEGIN@33 |
36 | { | ||||
37 | 2 | 500ns | $Data::DPath::Filters::VERSION = '0.49'; | ||
38 | } | ||||
39 | 1 | 2µs | 1 | 532µs | $COMPARTMENT = Safe->new; # spent 532µs making 1 call to Safe::new |
40 | 1 | 2µs | 1 | 13µs | $COMPARTMENT->permit(qw":base_core"); # spent 13µs making 1 call to Safe::permit |
41 | # map DPath filter functions into new namespace | ||||
42 | 1 | 6µs | 1 | 118µs | $COMPARTMENT->share(qw(affe # spent 118µs making 1 call to Safe::share |
43 | idx | ||||
44 | size | ||||
45 | key | ||||
46 | value | ||||
47 | isa | ||||
48 | reftype | ||||
49 | is_reftype | ||||
50 | )); | ||||
51 | 1 | 42µs | 1 | 680µs | } # spent 680µs making 1 call to Data::DPath::Context::BEGIN@29 |
52 | |||||
53 | # print "use $]\n" if $] >= 5.010; # allow new-school Perl inside filter expressions | ||||
54 | # eval "use $]" if $] >= 5.010; # allow new-school Perl inside filter expressions | ||||
55 | |||||
56 | use Class::XSAccessor::Array | ||||
57 | 1 | 11µs | 1 | 169µs | # spent 184µs (15+169) within Data::DPath::Context::BEGIN@57 which was called:
# once (15µs+169µs) by Data::DPath::Path::BEGIN@1.2 at line 62 # spent 169µs making 1 call to Class::XSAccessor::Array::import |
58 | constructor => 'new', | ||||
59 | accessors => { | ||||
60 | current_points => 0, | ||||
61 | give_references => 1, | ||||
62 | 1 | 64µs | 1 | 184µs | }; # spent 184µs making 1 call to Data::DPath::Context::BEGIN@57 |
63 | |||||
64 | 1 | 19µs | 1 | 206µs | # spent 225µs (19+206) within Data::DPath::Context::BEGIN@64 which was called:
# once (19µs+206µs) by Data::DPath::Path::BEGIN@1.2 at line 75 # spent 206µs making 1 call to constant::import |
65 | ARRAY => 'ARRAY', | ||||
66 | SCALAR => 'SCALAR', | ||||
67 | ROOT => 'ROOT', | ||||
68 | ANYWHERE => 'ANYWHERE', | ||||
69 | KEY => 'KEY', | ||||
70 | ANYSTEP => 'ANYSTEP', | ||||
71 | NOSTEP => 'NOSTEP', | ||||
72 | PARENT => 'PARENT', | ||||
73 | ANCESTOR => 'ANCESTOR', | ||||
74 | ANCESTOR_OR_SELF => 'ANCESTOR_OR_SELF', | ||||
75 | 1 | 181µs | 1 | 225µs | }; # spent 225µs making 1 call to Data::DPath::Context::BEGIN@64 |
76 | |||||
77 | sub _splice_threads { | ||||
78 | my ($cargo) = @_; | ||||
79 | |||||
80 | my $nr_cargo = @$cargo; | ||||
81 | |||||
82 | return [[]] unless $nr_cargo; | ||||
83 | |||||
84 | my $threadcount = $THREADCOUNT || 1; | ||||
85 | my $blocksize = ceil ($nr_cargo / $threadcount); | ||||
86 | |||||
87 | my @result = map { | ||||
88 | my $first = $_ * $blocksize; | ||||
89 | my $last = min(($_+1) * $blocksize - 1, $nr_cargo-1); | ||||
90 | ($first <= $last) ? [ @$cargo[$first .. $last]] : (); | ||||
91 | } 0 .. $threadcount-1; | ||||
92 | |||||
93 | return \@result; | ||||
94 | } | ||||
95 | |||||
96 | # only finds "inner" values; if you need the outer start value | ||||
97 | # then just wrap it into one more level of array brackets. | ||||
98 | sub _any | ||||
99 | { | ||||
100 | 8 | 7µs | my ($out, $in, $lookahead_key) = @_; | ||
101 | |||||
102 | 2 | 422µs | 2 | 52µs | # spent 34µs (16+18) within Data::DPath::Context::BEGIN@102 which was called:
# once (16µs+18µs) by Data::DPath::Path::BEGIN@1.2 at line 102 # spent 34µs making 1 call to Data::DPath::Context::BEGIN@102
# spent 18µs making 1 call to warnings::unimport |
103 | |||||
104 | 8 | 3µs | $in = defined $in ? $in : []; | ||
105 | 8 | 9µs | return @$out unless @$in; | ||
106 | |||||
107 | 7 | 1µs | my @newin; | ||
108 | 7 | 700ns | my @newout; | ||
109 | 7 | 1µs | my $tmp_ref; | ||
110 | 7 | 700ns | my $tmp_deref; | ||
111 | 7 | 900ns | my $tmp_reftype; | ||
112 | |||||
113 | 7 | 9µs | foreach my $point (@$in) { | ||
114 | 22 | 3µs | my @values; | ||
115 | 22 | 3µs | next unless defined $point; | ||
116 | 22 | 20µs | 1 | 2µs | my $ref = $point->ref; # spent 2µs making 1 call to Data::DPath::Point::ref |
117 | |||||
118 | # speed optimization: first try faster ref, then reftype | ||||
119 | 22 | 184µs | 34 | 24µs | if (ref($$ref) eq HASH or reftype($$ref) eq HASH) { # spent 24µs making 34 calls to Scalar::Util::reftype, avg 712ns/call |
120 | @values = | ||||
121 | map { { val_ref => \($$ref->{$_}), key => $_ } } | ||||
122 | grep { | ||||
123 | # speed optimization: only consider a key if lookahead looks promising | ||||
124 | not defined $lookahead_key | ||||
125 | or $_ eq $lookahead_key | ||||
126 | or ($tmp_ref = ref($tmp_deref =$$ref->{$_})) eq HASH | ||||
127 | or $tmp_ref eq ARRAY | ||||
128 | or ($tmp_reftype = reftype($tmp_deref)) eq HASH | ||||
129 | or $tmp_reftype eq ARRAY | ||||
130 | # or HASH_or_ARRAY(\($$ref->{$_})) | ||||
131 | } | ||||
132 | keys %{$$ref}; | ||||
133 | } | ||||
134 | elsif (ref($$ref) eq ARRAY or reftype($$ref) eq ARRAY) { | ||||
135 | 14 | 15µs | @values = map { { val_ref => \$_ } } @{$$ref} | ||
136 | } | ||||
137 | else { | ||||
138 | next | ||||
139 | 12 | 6µs | } | ||
140 | |||||
141 | 10 | 20µs | foreach (@values) | ||
142 | { | ||||
143 | 21 | 11µs | my $key = $_->{key}; | ||
144 | 21 | 6µs | my $val_ref = $_->{val_ref}; | ||
145 | 21 | 144µs | 3 | 7µs | my $newpoint = Point->new->ref($val_ref)->parent($point); # spent 3µs making 1 call to Data::DPath::Point::new
# spent 2µs making 1 call to Data::DPath::Point::parent
# spent 1µs making 1 call to Data::DPath::Point::ref |
146 | 21 | 59µs | 2 | 16µs | $newpoint->attrs( Attrs->new(key => $key)) if $key; # spent 14µs making 1 call to Data::DPath::Attrs::new
# spent 2µs making 1 call to Data::DPath::Point::attrs |
147 | 21 | 9µs | push @newout, $newpoint; | ||
148 | 21 | 19µs | push @newin, $newpoint; | ||
149 | } | ||||
150 | } | ||||
151 | 7 | 5µs | push @$out, @newout; | ||
152 | 7 | 55µs | 7 | 0s | return _any ($out, \@newin, $lookahead_key); # spent 2.03ms making 7 calls to Data::DPath::Context::_any, avg 290µs/call, recursion: max depth 7, sum of overlapping time 2.03ms |
153 | } | ||||
154 | |||||
155 | # spent 54µs (34+21) within Data::DPath::Context::_all which was called 2 times, avg 27µs/call:
# 2 times (34µs+21µs) by Data::DPath::Context::match at line 475, avg 27µs/call | ||||
156 | 2 | 1µs | my ($self) = @_; | ||
157 | |||||
158 | 2 | 35µs | 2 | 51µs | # spent 32µs (14+19) within Data::DPath::Context::BEGIN@158 which was called:
# once (14µs+19µs) by Data::DPath::Path::BEGIN@1.2 at line 158 # spent 32µs making 1 call to Data::DPath::Context::BEGIN@158
# spent 18µs making 1 call to strict::unimport |
159 | 2 | 202µs | 2 | 35µs | # spent 24µs (12+12) within Data::DPath::Context::BEGIN@159 which was called:
# once (12µs+12µs) by Data::DPath::Path::BEGIN@1.2 at line 159 # spent 24µs making 1 call to Data::DPath::Context::BEGIN@159
# spent 12µs making 1 call to warnings::unimport |
160 | |||||
161 | return | ||||
162 | 2 | 6µs | 1 | 1µs | map { $self->give_references ? $_ : $$_ } # spent 1µs making 1 call to Data::DPath::Point::ref |
163 | uniq | ||||
164 | map { defined $_ ? $_->ref : () } | ||||
165 | 2 | 50µs | 4 | 20µs | @{$self->current_points}; # spent 17µs making 2 calls to List::MoreUtils::uniq, avg 8µs/call
# spent 2µs making 1 call to Data::DPath::Context::current_points
# spent 900ns making 1 call to Data::DPath::Context::give_references |
166 | } | ||||
167 | |||||
168 | # filter current results by array index | ||||
169 | # spent 9µs within Data::DPath::Context::_filter_points_index which was called 2 times, avg 5µs/call:
# 2 times (9µs+0s) by Data::DPath::Context::_filter_points at line 232, avg 5µs/call | ||||
170 | 2 | 2µs | my ($self, $index, $points) = @_; | ||
171 | |||||
172 | 2 | 11µs | return $points ? [$points->[$index]] : []; | ||
173 | } | ||||
174 | |||||
175 | # filter current results by condition | ||||
176 | sub _filter_points_eval | ||||
177 | { | ||||
178 | my ($self, $filter, $points) = @_; | ||||
179 | |||||
180 | return [] unless @$points; | ||||
181 | return $points unless defined $filter; | ||||
182 | |||||
183 | my $new_points; | ||||
184 | my $res; | ||||
185 | { | ||||
186 | package Data::DPath::Filters; | ||||
187 | |||||
188 | local our $idx = 0; | ||||
189 | $new_points = [ | ||||
190 | grep { | ||||
191 | local our $p = $_; | ||||
192 | local $_; | ||||
193 | my $pref = $p->ref; | ||||
194 | if ( defined $pref ) { | ||||
195 | $_ = $$pref; | ||||
196 | if ($Data::DPath::USE_SAFE) { | ||||
197 | # 'uninitialized' values are the norm | ||||
198 | # but "no warnings 'uninitialized'" does | ||||
199 | # not work in this restrictive Safe.pm config, so | ||||
200 | # we deactivate warnings completely by localizing $^W | ||||
201 | $res = $COMPARTMENT->reval('local $^W;'.$filter); | ||||
202 | } else { | ||||
203 | # 'uninitialized' values are the norm | ||||
204 | 2 | 87µs | 2 | 59µs | # spent 36µs (13+23) within Data::DPath::Filters::BEGIN@204 which was called:
# once (13µs+23µs) by Data::DPath::Path::BEGIN@1.2 at line 204 # spent 36µs making 1 call to Data::DPath::Filters::BEGIN@204
# spent 23µs making 1 call to warnings::unimport |
205 | $res = eval($filter); | ||||
206 | } | ||||
207 | print STDERR ($@, "\n") if $@; | ||||
208 | } else { | ||||
209 | $res = 0; | ||||
210 | } | ||||
211 | $idx++; | ||||
212 | $res; | ||||
213 | } @$points | ||||
214 | ]; | ||||
215 | } | ||||
216 | return $new_points; | ||||
217 | } | ||||
218 | |||||
219 | # spent 146µs (117+29) within Data::DPath::Context::_filter_points which was called 29 times, avg 5µs/call:
# 18 times (42µs+0s) by Data::DPath::Context::_select_key at line 296, avg 2µs/call
# 6 times (20µs+2µs) by Data::DPath::Context::_select_root at line 251, avg 4µs/call
# 2 times (47µs+27µs) by Data::DPath::Context::_select_anystep at line 330, avg 37µs/call
# 2 times (5µs+0s) by Data::DPath::Context::_select_ancestor at line 368, avg 2µs/call
# once (3µs+0s) by Data::DPath::Context::_select_anywhere at line 271 | ||||
220 | 29 | 14µs | my ($self, $step, $points) = @_; | ||
221 | |||||
222 | 2 | 21µs | 2 | 26µs | # spent 17µs (8+9) within Data::DPath::Context::BEGIN@222 which was called:
# once (8µs+9µs) by Data::DPath::Path::BEGIN@1.2 at line 222 # spent 17µs making 1 call to Data::DPath::Context::BEGIN@222
# spent 9µs making 1 call to strict::unimport |
223 | 2 | 210µs | 2 | 22µs | # spent 15µs (8+7) within Data::DPath::Context::BEGIN@223 which was called:
# once (8µs+7µs) by Data::DPath::Path::BEGIN@1.2 at line 223 # spent 15µs making 1 call to Data::DPath::Context::BEGIN@223
# spent 7µs making 1 call to warnings::unimport |
224 | |||||
225 | 29 | 26µs | return [] unless @$points; | ||
226 | |||||
227 | 23 | 17µs | 1 | 2µs | my $filter = $step->filter; # spent 2µs making 1 call to Data::DPath::Step::filter |
228 | 23 | 71µs | return $points unless defined $filter; | ||
229 | |||||
230 | 2 | 36µs | 6 | 13µs | $filter =~ s/^\[\s*(.*?)\s*\]$/$1/; # strip brackets and whitespace # spent 8µs making 2 calls to Data::DPath::Context::CORE:subst, avg 4µs/call
# spent 4µs making 4 calls to Data::DPath::Context::CORE:substcont, avg 1µs/call |
231 | |||||
232 | 2 | 26µs | 4 | 15µs | if ($filter =~ /^-?\d+$/) # spent 9µs making 2 calls to Data::DPath::Context::_filter_points_index, avg 5µs/call
# spent 5µs making 2 calls to Data::DPath::Context::CORE:match, avg 3µs/call |
233 | { | ||||
234 | return $self->_filter_points_index($filter, $points); # simple array index | ||||
235 | } | ||||
236 | elsif ($filter =~ /\S/) | ||||
237 | { | ||||
238 | return $self->_filter_points_eval($filter, $points); # full condition | ||||
239 | } | ||||
240 | else | ||||
241 | { | ||||
242 | return $points; | ||||
243 | } | ||||
244 | } | ||||
245 | |||||
246 | # the root node | ||||
247 | # (only makes sense at first step, but currently not asserted) | ||||
248 | # spent 65µs (43+23) within Data::DPath::Context::_select_root which was called 6 times, avg 11µs/call:
# 6 times (43µs+23µs) by Data::DPath::Context::_search at line 434, avg 11µs/call | ||||
249 | 6 | 4µs | my ($self, $step, $current_points, $new_points) = @_; | ||
250 | |||||
251 | 6 | 9µs | 6 | 23µs | my $step_points = $self->_filter_points($step, $current_points); # spent 23µs making 6 calls to Data::DPath::Context::_filter_points, avg 4µs/call |
252 | 6 | 23µs | push @$new_points, @$step_points; | ||
253 | } | ||||
254 | |||||
255 | |||||
256 | # // | ||||
257 | # anywhere in the tree | ||||
258 | # spent 631µs (34+596) within Data::DPath::Context::_select_anywhere which was called:
# once (34µs+596µs) by Data::DPath::Context::_search at line 434 | ||||
259 | 1 | 1µs | my ($self, $step, $current_points, $lookahead, $new_points) = @_; | ||
260 | |||||
261 | # speed optimization: only useful points added | ||||
262 | 1 | 300ns | my $lookahead_key; | ||
263 | 1 | 12µs | 2 | 2µs | if (defined $lookahead and $lookahead->kind eq KEY) { # spent 2µs making 1 call to Data::DPath::Step::kind
# spent 800ns making 1 call to Data::DPath::Step::part |
264 | $lookahead_key = $lookahead->part; | ||||
265 | } | ||||
266 | |||||
267 | # '//' | ||||
268 | # all hash/array nodes of a data structure | ||||
269 | 1 | 8µs | foreach my $point (@$current_points) { | ||
270 | 1 | 9µs | 1 | 591µs | my $step_points = [_any([], [ $point ], $lookahead_key), $point]; # spent 591µs making 1 call to Data::DPath::Context::_any |
271 | 1 | 6µs | 1 | 3µs | push @$new_points, @{$self->_filter_points($step, $step_points)}; # spent 3µs making 1 call to Data::DPath::Context::_filter_points |
272 | } | ||||
273 | } | ||||
274 | |||||
275 | # /key | ||||
276 | # the value of a key | ||||
277 | # spent 425µs (362+63) within Data::DPath::Context::_select_key which was called 11 times, avg 39µs/call:
# 11 times (362µs+63µs) by Data::DPath::Context::_search at line 434, avg 39µs/call | ||||
278 | 11 | 6µs | my ($self, $step, $current_points, $new_points) = @_; | ||
279 | |||||
280 | 11 | 40µs | foreach my $point (@$current_points) { | ||
281 | 2 | 114µs | 2 | 24µs | # spent 16µs (9+7) within Data::DPath::Context::BEGIN@281 which was called:
# once (9µs+7µs) by Data::DPath::Path::BEGIN@1.2 at line 281 # spent 16µs making 1 call to Data::DPath::Context::BEGIN@281
# spent 8µs making 1 call to warnings::unimport |
282 | 32 | 5µs | next unless defined $point; | ||
283 | 32 | 23µs | 1 | 900ns | my $pref = $point->ref; # spent 900ns making 1 call to Data::DPath::Point::ref |
284 | next unless ( | ||||
285 | # speed optimization: | ||||
286 | # first try faster ref, then reftype | ||||
287 | 32 | 60µs | 14 | 10µs | ref($$pref) eq HASH or # spent 10µs making 14 calls to Scalar::Util::reftype, avg 700ns/call |
288 | reftype($$pref) eq HASH | ||||
289 | ); | ||||
290 | # take point as hash, skip undefs | ||||
291 | 18 | 73µs | 2 | 3µs | my $attrs = Attrs->new(key => $step->part); # spent 2µs making 1 call to Data::DPath::Attrs::new
# spent 700ns making 1 call to Data::DPath::Step::part |
292 | 18 | 7µs | my $step_points = []; | ||
293 | 18 | 97µs | 6 | 8µs | if (exists $$pref->{$step->part}) { # spent 3µs making 2 calls to Data::DPath::Step::part, avg 1µs/call
# spent 2µs making 1 call to Data::DPath::Point::new
# spent 1µs making 1 call to Data::DPath::Point::ref
# spent 1µs making 1 call to Data::DPath::Point::parent
# spent 900ns making 1 call to Data::DPath::Point::attrs |
294 | $step_points = [ Point->new->ref(\($$pref->{$step->part}))->parent($point)->attrs($attrs) ]; | ||||
295 | } | ||||
296 | 18 | 56µs | 18 | 42µs | push @$new_points, @{$self->_filter_points($step, $step_points)}; # spent 42µs making 18 calls to Data::DPath::Context::_filter_points, avg 2µs/call |
297 | } | ||||
298 | } | ||||
299 | |||||
300 | # '*' | ||||
301 | # all leaves of a data tree | ||||
302 | # spent 184µs (101+83) within Data::DPath::Context::_select_anystep which was called 2 times, avg 92µs/call:
# 2 times (101µs+83µs) by Data::DPath::Context::_search at line 434, avg 92µs/call | ||||
303 | 2 | 2µs | my ($self, $step, $current_points, $new_points) = @_; | ||
304 | |||||
305 | 2 | 461µs | 2 | 22µs | # spent 15µs (8+7) within Data::DPath::Context::BEGIN@305 which was called:
# once (8µs+7µs) by Data::DPath::Path::BEGIN@1.2 at line 305 # spent 15µs making 1 call to Data::DPath::Context::BEGIN@305
# spent 7µs making 1 call to warnings::unimport |
306 | 2 | 10µs | foreach my $point (@$current_points) { | ||
307 | # take point as array | ||||
308 | 2 | 7µs | 1 | 1µs | my $pref = $point->ref; # spent 1µs making 1 call to Data::DPath::Point::ref |
309 | 2 | 900ns | my $ref = $$pref; | ||
310 | 2 | 1µs | my $step_points = []; | ||
311 | # speed optimization: first try faster ref, then reftype | ||||
312 | 2 | 14µs | 2 | 3µs | if (ref($ref) eq HASH or reftype($ref) eq HASH) { # spent 3µs making 2 calls to Scalar::Util::reftype, avg 1µs/call |
313 | $step_points = [ map { | ||||
314 | my $v_ref = \($ref->{$_}); | ||||
315 | my $attrs = Attrs->new(key => $_); | ||||
316 | Point->new->ref($v_ref)->parent($point)->attrs($attrs) | ||||
317 | } keys %$ref ]; | ||||
318 | } elsif (ref($ref) eq ARRAY or reftype($ref) eq ARRAY) { | ||||
319 | 12 | 53µs | 3 | 5µs | $step_points = [ map { # spent 3µs making 1 call to Data::DPath::Point::new
# spent 1µs making 1 call to Data::DPath::Point::parent
# spent 1µs making 1 call to Data::DPath::Point::ref |
320 | 2 | 11µs | Point->new->ref(\$_)->parent($point) | ||
321 | } @$ref ]; | ||||
322 | } else { | ||||
323 | if (ref($pref) eq SCALAR or reftype($pref) eq SCALAR) { | ||||
324 | # TODO: without map, it's just one value | ||||
325 | $step_points = [ #map { | ||||
326 | Point->new->ref($pref)->parent($point) # XXX? why $_? What happens to $pref? | ||||
327 | ]; # } $ref ]; | ||||
328 | } | ||||
329 | } | ||||
330 | 2 | 11µs | 2 | 74µs | push @$new_points, @{ $self->_filter_points($step, $step_points) }; # spent 74µs making 2 calls to Data::DPath::Context::_filter_points, avg 37µs/call |
331 | } | ||||
332 | } | ||||
333 | |||||
334 | # '.' | ||||
335 | # no step (neither up nor down), just allow filtering | ||||
336 | sub _select_nostep { | ||||
337 | my ($self, $step, $current_points, $new_points) = @_; | ||||
338 | |||||
339 | foreach my $point (@{$current_points}) { | ||||
340 | my $step_points = [$point]; | ||||
341 | push @$new_points, @{ $self->_filter_points($step, $step_points) }; | ||||
342 | } | ||||
343 | } | ||||
344 | |||||
345 | # '..' | ||||
346 | # the parent | ||||
347 | sub _select_parent { | ||||
348 | my ($self, $step, $current_points, $new_points) = @_; | ||||
349 | |||||
350 | foreach my $point (@{$current_points}) { | ||||
351 | next unless defined $point; | ||||
352 | my $step_points = [$point->parent]; | ||||
353 | push @$new_points, @{ $self->_filter_points($step, $step_points) }; | ||||
354 | } | ||||
355 | } | ||||
356 | |||||
357 | # '::ancestor' | ||||
358 | # all ancestors (parent, grandparent, etc.) of the current node | ||||
359 | # spent 46µs (40+7) within Data::DPath::Context::_select_ancestor which was called 2 times, avg 23µs/call:
# 2 times (40µs+7µs) by Data::DPath::Context::_search at line 434, avg 23µs/call | ||||
360 | 2 | 2µs | my ($self, $step, $current_points, $new_points) = @_; | ||
361 | |||||
362 | 2 | 9µs | foreach my $point (@{$current_points}) { | ||
363 | 2 | 1µs | my $step_points = []; | ||
364 | 2 | 400ns | my $parent = $point; | ||
365 | 2 | 9µs | 1 | 2µs | while ($parent = $parent->parent) { # spent 2µs making 1 call to Data::DPath::Point::parent |
366 | 10 | 9µs | push @$step_points, $parent; # order matters | ||
367 | } | ||||
368 | 2 | 8µs | 2 | 5µs | push @$new_points, @{ $self->_filter_points($step, $step_points) }; # spent 5µs making 2 calls to Data::DPath::Context::_filter_points, avg 2µs/call |
369 | } | ||||
370 | } | ||||
371 | |||||
372 | # '::ancestor-or-self' | ||||
373 | # all ancestors (parent, grandparent, etc.) of the current node and the current node itself | ||||
374 | sub _select_ancestor_or_self { | ||||
375 | my ($self, $step, $current_points, $new_points) = @_; | ||||
376 | |||||
377 | foreach my $point (@{$current_points}) { | ||||
378 | my $step_points = [$point]; | ||||
379 | my $parent = $point; | ||||
380 | while ($parent = $parent->parent) { | ||||
381 | push @$step_points, $parent; # order matters | ||||
382 | } | ||||
383 | push @$new_points, @{ $self->_filter_points($step, $step_points) }; | ||||
384 | } | ||||
385 | } | ||||
386 | |||||
387 | sub ref { | ||||
388 | my ($self) = @_; | ||||
389 | $self->first_point->{ref}; | ||||
390 | } | ||||
391 | |||||
392 | sub deref { | ||||
393 | my ($self) = @_; | ||||
394 | ${$self->ref}; | ||||
395 | } | ||||
396 | |||||
397 | # spent 29µs (28+800ns) within Data::DPath::Context::first_point which was called 10 times, avg 3µs/call:
# 10 times (28µs+800ns) by Benchmark::Perl::Formance::find_interesting_result_paths at line 706 of lib/Benchmark/Perl/Formance.pm, avg 3µs/call | ||||
398 | 10 | 5µs | my ($self) = @_; | ||
399 | 10 | 39µs | 1 | 800ns | $self->current_points->[0]; # spent 800ns making 1 call to Data::DPath::Context::current_points |
400 | } | ||||
401 | |||||
402 | sub all_points { | ||||
403 | my ($self) = @_; | ||||
404 | iarray $self->current_points; | ||||
405 | } | ||||
406 | |||||
407 | # spent 1.61ms (49µs+1.56) within Data::DPath::Context::_iter which was called 4 times, avg 403µs/call:
# 3 times (27µs+332µs) by Data::DPath::Context::isearch at line 417, avg 120µs/call
# once (22µs+1.23ms) by Data::DPath::__ANON__[/home/ss5/perl5/perlbrew/perls/tapper-perl/lib/site_perl/5.16.3/Data/DPath.pm:47] at line 41 of Data/DPath.pm | ||||
408 | 4 | 2µs | my ($self) = @_; | ||
409 | |||||
410 | 4 | 19µs | 5 | 218µs | my $iter = iarray $self->current_points; # spent 216µs making 4 calls to Iterator::Util::iarray, avg 54µs/call
# spent 2µs making 1 call to Data::DPath::Context::current_points |
411 | 17 | 136µs | 6 | 1.35ms | # spent 79µs (75+4) within Data::DPath::Context::__ANON__[/home/ss5/perl5/perlbrew/perls/tapper-perl/lib/site_perl/5.16.3/Data/DPath/Context.pm:411] which was called 13 times, avg 6µs/call:
# 13 times (75µs+4µs) by Iterator::Util::__ANON__[/home/ss5/perl5/perlbrew/perls/tapper-perl/lib/site_perl/5.16.3/Iterator/Util.pm:52] at line 51 of Iterator/Util.pm, avg 6µs/call # spent 1.34ms making 4 calls to Iterator::Util::imap, avg 336µs/call
# spent 2µs making 1 call to Data::DPath::Context::new
# spent 1µs making 1 call to Data::DPath::Context::current_points |
412 | } | ||||
413 | |||||
414 | sub isearch | ||||
415 | # spent 1.92ms (45µs+1.87) within Data::DPath::Context::isearch which was called 3 times, avg 639µs/call:
# 2 times (26µs+571µs) by Benchmark::Perl::Formance::find_interesting_result_paths at line 703 of lib/Benchmark/Perl/Formance.pm, avg 298µs/call
# once (19µs+1.30ms) by Benchmark::Perl::Formance::find_interesting_result_paths at line 698 of lib/Benchmark/Perl/Formance.pm | ||||
416 | 3 | 2µs | my ($self, $path_str) = @_; | ||
417 | 3 | 31µs | 9 | 1.87ms | $self->_search(Data::DPath::Path->new(path => $path_str))->_iter; # spent 1.03ms making 3 calls to Data::DPath::Context::_search, avg 344µs/call
# spent 481µs making 3 calls to Data::DPath::Path::new, avg 160µs/call
# spent 359µs making 3 calls to Data::DPath::Context::_iter, avg 120µs/call |
418 | } | ||||
419 | |||||
420 | sub _search | ||||
421 | # spent 1.59ms (231µs+1.36) within Data::DPath::Context::_search which was called 6 times, avg 266µs/call:
# 3 times (96µs+936µs) by Data::DPath::Context::isearch at line 417, avg 344µs/call
# 2 times (100µs+399µs) by Data::DPath::Context::match at line 475, avg 249µs/call
# once (35µs+29µs) by Data::DPath::__ANON__[/home/ss5/perl5/perlbrew/perls/tapper-perl/lib/site_perl/5.16.3/Data/DPath.pm:47] at line 41 of Data/DPath.pm | ||||
422 | 6 | 3µs | my ($self, $dpath) = @_; | ||
423 | |||||
424 | 2 | 20µs | 2 | 26µs | # spent 17µs (7+10) within Data::DPath::Context::BEGIN@424 which was called:
# once (7µs+10µs) by Data::DPath::Path::BEGIN@1.2 at line 424 # spent 17µs making 1 call to Data::DPath::Context::BEGIN@424
# spent 10µs making 1 call to strict::unimport |
425 | 2 | 188µs | 2 | 23µs | # spent 16µs (10+7) within Data::DPath::Context::BEGIN@425 which was called:
# once (10µs+7µs) by Data::DPath::Path::BEGIN@1.2 at line 425 # spent 16µs making 1 call to Data::DPath::Context::BEGIN@425
# spent 7µs making 1 call to warnings::unimport |
426 | |||||
427 | 6 | 10µs | 1 | 2µs | my $current_points = $self->current_points; # spent 2µs making 1 call to Data::DPath::Context::current_points |
428 | 6 | 8µs | 1 | 900ns | my $steps = $dpath->_steps; # spent 900ns making 1 call to Data::DPath::Path::_steps |
429 | 6 | 27µs | for (my $i = 0; $i < @$steps; $i++) { | ||
430 | 22 | 8µs | my $step = $steps->[$i]; | ||
431 | 22 | 10µs | my $lookahead = $steps->[$i+1]; | ||
432 | 22 | 10µs | my $new_points = []; | ||
433 | |||||
434 | 22 | 99µs | 29 | 1.36ms | if ($step->kind eq ROOT) # spent 631µs making 1 call to Data::DPath::Context::_select_anywhere
# spent 425µs making 11 calls to Data::DPath::Context::_select_key, avg 39µs/call
# spent 184µs making 2 calls to Data::DPath::Context::_select_anystep, avg 92µs/call
# spent 65µs making 6 calls to Data::DPath::Context::_select_root, avg 11µs/call
# spent 46µs making 2 calls to Data::DPath::Context::_select_ancestor, avg 23µs/call
# spent 7µs making 7 calls to Data::DPath::Step::kind, avg 1µs/call |
435 | { | ||||
436 | $self->_select_root($step, $current_points, $new_points); | ||||
437 | } | ||||
438 | elsif ($step->kind eq ANYWHERE) | ||||
439 | { | ||||
440 | $self->_select_anywhere($step, $current_points, $lookahead, $new_points); | ||||
441 | } | ||||
442 | elsif ($step->kind eq KEY) | ||||
443 | { | ||||
444 | $self->_select_key($step, $current_points, $new_points); | ||||
445 | } | ||||
446 | elsif ($step->kind eq ANYSTEP) | ||||
447 | { | ||||
448 | $self->_select_anystep($step, $current_points, $new_points); | ||||
449 | } | ||||
450 | elsif ($step->kind eq NOSTEP) | ||||
451 | { | ||||
452 | $self->_select_nostep($step, $current_points, $new_points); | ||||
453 | } | ||||
454 | elsif ($step->kind eq PARENT) | ||||
455 | { | ||||
456 | $self->_select_parent($step, $current_points, $new_points); | ||||
457 | } | ||||
458 | elsif ($step->kind eq ANCESTOR) | ||||
459 | { | ||||
460 | $self->_select_ancestor($step, $current_points, $new_points); | ||||
461 | } | ||||
462 | elsif ($step->kind eq ANCESTOR_OR_SELF) | ||||
463 | { | ||||
464 | $self->_select_ancestor_or_self($step, $current_points, $new_points); | ||||
465 | } | ||||
466 | 22 | 13µs | $current_points = $new_points; | ||
467 | } | ||||
468 | 6 | 12µs | 1 | 2µs | $self->current_points( $current_points ); # spent 2µs making 1 call to Data::DPath::Context::current_points |
469 | 6 | 26µs | return $self; | ||
470 | } | ||||
471 | |||||
472 | # spent 572µs (19+553) within Data::DPath::Context::match which was called 2 times, avg 286µs/call:
# 2 times (19µs+553µs) by Data::DPath::Path::match at line 143 of Data/DPath/Path.pm, avg 286µs/call | ||||
473 | 2 | 1µs | my ($self, $dpath) = @_; | ||
474 | |||||
475 | 2 | 16µs | 4 | 553µs | $self->_search($dpath)->_all; # spent 499µs making 2 calls to Data::DPath::Context::_search, avg 249µs/call
# spent 54µs making 2 calls to Data::DPath::Context::_all, avg 27µs/call |
476 | } | ||||
477 | |||||
478 | 1 | 3µs | 1; | ||
479 | |||||
480 | __END__ | ||||
# spent 5µs within Data::DPath::Context::CORE:match which was called 2 times, avg 3µs/call:
# 2 times (5µs+0s) by Data::DPath::Context::_filter_points at line 232, avg 3µs/call | |||||
# spent 8µs within Data::DPath::Context::CORE:subst which was called 2 times, avg 4µs/call:
# 2 times (8µs+0s) by Data::DPath::Context::_filter_points at line 230, avg 4µs/call | |||||
# spent 4µs within Data::DPath::Context::CORE:substcont which was called 4 times, avg 1µs/call:
# 4 times (4µs+0s) by Data::DPath::Context::_filter_points at line 230, avg 1µs/call | |||||
# spent 14µs within Data::DPath::Context::current_points which was called 8 times, avg 2µs/call:
# once (4µs+0s) by Data::DPath::__ANON__[/home/ss5/perl5/perlbrew/perls/tapper-perl/lib/site_perl/5.16.3/Data/DPath.pm:47] at line 41 of Data/DPath.pm
# once (2µs+0s) by Data::DPath::Context::_search at line 468
# once (2µs+0s) by Data::DPath::Context::_all at line 165
# once (2µs+0s) by Data::DPath::Context::_search at line 427
# once (2µs+0s) by Data::DPath::Context::_iter at line 410
# once (1µs+0s) by Data::DPath::Path::match at line 139 of Data/DPath/Path.pm
# once (1µs+0s) by Data::DPath::Context::__ANON__[/home/ss5/perl5/perlbrew/perls/tapper-perl/lib/site_perl/5.16.3/Data/DPath/Context.pm:411] at line 411
# once (800ns+0s) by Data::DPath::Context::first_point at line 399 | |||||
# spent 2µs within Data::DPath::Context::give_references which was called 2 times, avg 800ns/call:
# once (900ns+0s) by Data::DPath::Context::_all at line 165
# once (700ns+0s) by Data::DPath::Path::match at line 139 of Data/DPath/Path.pm | |||||
# spent 28µs within Data::DPath::Context::new which was called 3 times, avg 9µs/call:
# once (24µs+0s) by Data::DPath::__ANON__[/home/ss5/perl5/perlbrew/perls/tapper-perl/lib/site_perl/5.16.3/Data/DPath.pm:47] at line 41 of Data/DPath.pm
# once (2µs+0s) by Data::DPath::Path::match at line 139 of Data/DPath/Path.pm
# once (2µs+0s) by Data::DPath::Context::__ANON__[/home/ss5/perl5/perlbrew/perls/tapper-perl/lib/site_perl/5.16.3/Data/DPath/Context.pm:411] at line 411 |