| Filename | /Users/ap13/perl5/lib/perl5/Graph/AdjacencyMap/Light.pm |
| Statements | Executed 887776 statements in 573ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 34911 | 2 | 1 | 226ms | 236ms | Graph::AdjacencyMap::Light::set_path |
| 49752 | 2 | 1 | 140ms | 140ms | Graph::AdjacencyMap::Light::_get_path_id |
| 50238 | 2 | 2 | 137ms | 137ms | Graph::AdjacencyMap::Light::_get_id_path |
| 210 | 2 | 1 | 16.9ms | 16.9ms | Graph::AdjacencyMap::Light::paths |
| 35195 | 2 | 1 | 15.8ms | 15.8ms | Graph::AdjacencyMap::Light::_is_MULTI (xsub) |
| 9977 | 1 | 1 | 9.81ms | 9.81ms | Graph::AdjacencyMap::Light::CORE:sort (opcode) |
| 224 | 2 | 1 | 2.34ms | 2.72ms | Graph::AdjacencyMap::Light::_new |
| 67 | 1 | 1 | 2.11ms | 13.9ms | Graph::AdjacencyMap::Light::__attr |
| 1 | 1 | 1 | 1.08ms | 1.43ms | Graph::AdjacencyMap::Light::BEGIN@15 |
| 179 | 2 | 1 | 96µs | 96µs | Graph::AdjacencyMap::Light::_is_COUNT (xsub) |
| 76 | 1 | 1 | 95µs | 95µs | Graph::AdjacencyMap::Light::_is_HYPER (xsub) |
| 1 | 1 | 1 | 13µs | 26µs | Graph::AdjacencyMap::Light::BEGIN@7 |
| 1 | 1 | 1 | 10µs | 34µs | Graph::AdjacencyMap::Light::BEGIN@12 |
| 1 | 1 | 1 | 9µs | 67µs | Graph::AdjacencyMap::Light::BEGIN@10 |
| 1 | 1 | 1 | 8µs | 252µs | Graph::AdjacencyMap::Light::BEGIN@9 |
| 1 | 1 | 1 | 8µs | 19µs | Graph::AdjacencyMap::Light::BEGIN@14 |
| 0 | 0 | 0 | 0s | 0s | Graph::AdjacencyMap::Light::__predecessors |
| 0 | 0 | 0 | 0s | 0s | Graph::AdjacencyMap::Light::__successors |
| 0 | 0 | 0 | 0s | 0s | Graph::AdjacencyMap::Light::_get_path_count |
| 0 | 0 | 0 | 0s | 0s | Graph::AdjacencyMap::Light::_predecessors |
| 0 | 0 | 0 | 0s | 0s | Graph::AdjacencyMap::Light::_successors |
| 0 | 0 | 0 | 0s | 0s | Graph::AdjacencyMap::Light::del_path |
| 0 | 0 | 0 | 0s | 0s | Graph::AdjacencyMap::Light::has_path |
| 0 | 0 | 0 | 0s | 0s | Graph::AdjacencyMap::Light::has_paths |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Graph::AdjacencyMap::Light; | ||||
| 2 | |||||
| 3 | # THIS IS INTERNAL IMPLEMENTATION ONLY, NOT TO BE USED DIRECTLY. | ||||
| 4 | # THE INTERFACE IS HARD TO USE AND GOING TO STAY THAT WAY AND | ||||
| 5 | # ALMOST GUARANTEED TO CHANGE OR GO AWAY IN FUTURE RELEASES. | ||||
| 6 | |||||
| 7 | 2 | 31µs | 2 | 39µs | # spent 26µs (13+13) within Graph::AdjacencyMap::Light::BEGIN@7 which was called:
# once (13µs+13µs) by Graph::BEGIN@29 at line 7 # spent 26µs making 1 call to Graph::AdjacencyMap::Light::BEGIN@7
# spent 13µs making 1 call to strict::import |
| 8 | |||||
| 9 | 2 | 28µs | 2 | 496µs | # spent 252µs (8+244) within Graph::AdjacencyMap::Light::BEGIN@9 which was called:
# once (8µs+244µs) by Graph::BEGIN@29 at line 9 # spent 252µs making 1 call to Graph::AdjacencyMap::Light::BEGIN@9
# spent 244µs making 1 call to Exporter::import |
| 10 | 2 | 26µs | 2 | 126µs | # spent 67µs (9+59) within Graph::AdjacencyMap::Light::BEGIN@10 which was called:
# once (9µs+59µs) by Graph::BEGIN@29 at line 10 # spent 67µs making 1 call to Graph::AdjacencyMap::Light::BEGIN@10
# spent 59µs making 1 call to base::import |
| 11 | |||||
| 12 | 2 | 25µs | 2 | 58µs | # spent 34µs (10+24) within Graph::AdjacencyMap::Light::BEGIN@12 which was called:
# once (10µs+24µs) by Graph::BEGIN@29 at line 12 # spent 34µs making 1 call to Graph::AdjacencyMap::Light::BEGIN@12
# spent 24µs making 1 call to Exporter::import |
| 13 | |||||
| 14 | 2 | 21µs | 2 | 31µs | # spent 19µs (8+11) within Graph::AdjacencyMap::Light::BEGIN@14 which was called:
# once (8µs+11µs) by Graph::BEGIN@29 at line 14 # spent 19µs making 1 call to Graph::AdjacencyMap::Light::BEGIN@14
# spent 12µs making 1 call to Exporter::import |
| 15 | 2 | 1.22ms | 2 | 1.45ms | # spent 1.43ms (1.08+352µs) within Graph::AdjacencyMap::Light::BEGIN@15 which was called:
# once (1.08ms+352µs) by Graph::BEGIN@29 at line 15 # spent 1.43ms making 1 call to Graph::AdjacencyMap::Light::BEGIN@15
# spent 17µs making 1 call to Exporter::import |
| 16 | |||||
| 17 | sub _V () { 2 } # Graph::_V | ||||
| 18 | sub _E () { 3 } # Graph::_E | ||||
| 19 | sub _F () { 0 } # Graph::_F | ||||
| 20 | |||||
| 21 | # spent 2.72ms (2.34+374µs) within Graph::AdjacencyMap::Light::_new which was called 224 times, avg 12µs/call:
# 112 times (1.44ms+271µs) by Graph::new at line 300 of Graph.pm, avg 15µs/call
# 112 times (902µs+103µs) by Graph::new at line 305 of Graph.pm, avg 9µs/call | ||||
| 22 | 2464 | 2.69ms | my ($class, $graph, $flags, $arity) = @_; | ||
| 23 | my $m = bless [ ], $class; | ||||
| 24 | $m->[ _n ] = 0; | ||||
| 25 | $m->[ _f ] = $flags | _LIGHT; | ||||
| 26 | $m->[ _a ] = $arity; | ||||
| 27 | $m->[ _i ] = { }; | ||||
| 28 | $m->[ _s ] = { }; | ||||
| 29 | $m->[ _p ] = { }; | ||||
| 30 | $m->[ _g ] = $graph; | ||||
| 31 | 224 | 374µs | weaken $m->[ _g ]; # So that DESTROY finds us earlier. # spent 374µs making 224 calls to Scalar::Util::weaken, avg 2µs/call | ||
| 32 | return $m; | ||||
| 33 | } | ||||
| 34 | |||||
| 35 | # spent 236ms (226+9.81) within Graph::AdjacencyMap::Light::set_path which was called 34911 times, avg 7µs/call:
# 24934 times (132ms+0s) by Graph::add_vertex at line 396 of Graph.pm, avg 5µs/call
# 9977 times (94.8ms+9.81ms) by Graph::add_edge at line 504 of Graph.pm, avg 10µs/call | ||||
| 36 | 174555 | 131ms | my $m = shift; | ||
| 37 | my ($n, $f, $a, $i, $s, $p) = @$m; | ||||
| 38 | 9977 | 9.81ms | if ($a == 2) { # spent 9.81ms making 9977 calls to Graph::AdjacencyMap::Light::CORE:sort, avg 984ns/call | ||
| 39 | @_ = sort @_ if ($f & _UNORD); | ||||
| 40 | } | ||||
| 41 | my $e0 = shift; | ||||
| 42 | 44888 | 14.2ms | if ($a == 2) { | ||
| 43 | my $e1 = shift; | ||||
| 44 | 39908 | 39.3ms | unless (exists $s->{ $e0 } && exists $s->{ $e0 }->{ $e1 }) { | ||
| 45 | $n = $m->[ _n ]++; | ||||
| 46 | $i->{ $n } = [ $e0, $e1 ]; | ||||
| 47 | $s->{ $e0 }->{ $e1 } = $n; | ||||
| 48 | $p->{ $e1 }->{ $e0 } = $n; | ||||
| 49 | } | ||||
| 50 | } else { | ||||
| 51 | 74802 | 45.3ms | unless (exists $s->{ $e0 }) { | ||
| 52 | $n = $m->[ _n ]++; | ||||
| 53 | $s->{ $e0 } = $n; | ||||
| 54 | $i->{ $n } = $e0; | ||||
| 55 | } | ||||
| 56 | } | ||||
| 57 | } | ||||
| 58 | |||||
| 59 | sub has_path { | ||||
| 60 | my $m = shift; | ||||
| 61 | my ($n, $f, $a, $i, $s) = @$m; | ||||
| 62 | return 0 unless $a == @_; | ||||
| 63 | my $e; | ||||
| 64 | if ($a == 2) { | ||||
| 65 | @_ = sort @_ if ($f & _UNORD); | ||||
| 66 | $e = shift; | ||||
| 67 | return 0 unless exists $s->{ $e }; | ||||
| 68 | $s = $s->{ $e }; | ||||
| 69 | } | ||||
| 70 | $e = shift; | ||||
| 71 | exists $s->{ $e }; | ||||
| 72 | } | ||||
| 73 | |||||
| 74 | # spent 140ms within Graph::AdjacencyMap::Light::_get_path_id which was called 49752 times, avg 3µs/call:
# 24876 times (75.4ms+0s) by Graph::_edges at line 812 of Graph.pm, avg 3µs/call
# 24876 times (64.5ms+0s) by Graph::_edges at line 817 of Graph.pm, avg 3µs/call | ||||
| 75 | 348264 | 154ms | my $m = shift; | ||
| 76 | my ($n, $f, $a, $i, $s) = @$m; | ||||
| 77 | return undef unless $a == @_; | ||||
| 78 | my $e; | ||||
| 79 | if ($a == 2) { | ||||
| 80 | @_ = sort @_ if ($f & _UNORD); | ||||
| 81 | $e = shift; | ||||
| 82 | return undef unless exists $s->{ $e }; | ||||
| 83 | $s = $s->{ $e }; | ||||
| 84 | } | ||||
| 85 | $e = shift; | ||||
| 86 | $s->{ $e }; | ||||
| 87 | } | ||||
| 88 | |||||
| 89 | sub _get_path_count { | ||||
| 90 | my $m = shift; | ||||
| 91 | my ($n, $f, $a, $i, $s) = @$m; | ||||
| 92 | my $e; | ||||
| 93 | if (@_ == 2) { | ||||
| 94 | @_ = sort @_ if ($f & _UNORD); | ||||
| 95 | $e = shift; | ||||
| 96 | return undef unless exists $s->{ $e }; | ||||
| 97 | $s = $s->{ $e }; | ||||
| 98 | } | ||||
| 99 | $e = shift; | ||||
| 100 | return exists $s->{ $e } ? 1 : 0; | ||||
| 101 | } | ||||
| 102 | |||||
| 103 | sub has_paths { | ||||
| 104 | my $m = shift; | ||||
| 105 | my ($n, $f, $a, $i, $s) = @$m; | ||||
| 106 | keys %$s; | ||||
| 107 | } | ||||
| 108 | |||||
| 109 | # spent 16.9ms within Graph::AdjacencyMap::Light::paths which was called 210 times, avg 80µs/call:
# 134 times (709µs+0s) by Graph::edges05 at line 557 of Graph.pm, avg 5µs/call
# 76 times (16.2ms+0s) by Graph::vertices05 at line 411 of Graph.pm, avg 213µs/call | ||||
| 110 | 630 | 274µs | my $m = shift; | ||
| 111 | my ($n, $f, $a, $i) = @$m; | ||||
| 112 | 420 | 637µs | if (defined $i) { | ||
| 113 | my ($k, $v) = each %$i; | ||||
| 114 | 143 | 16.2ms | if (ref $v) { | ||
| 115 | return values %{ $i }; | ||||
| 116 | } else { | ||||
| 117 | return map { [ $_ ] } values %{ $i }; | ||||
| 118 | } | ||||
| 119 | } else { | ||||
| 120 | return ( ); | ||||
| 121 | } | ||||
| 122 | } | ||||
| 123 | |||||
| 124 | # spent 137ms within Graph::AdjacencyMap::Light::_get_id_path which was called 50238 times, avg 3µs/call:
# 50037 times (136ms+0s) by Graph::AdjacencyMap::_successors at line 396 of Graph/AdjacencyMap.pm, avg 3µs/call
# 201 times (607µs+0s) by Graph::edges05 at line 559 of Graph.pm, avg 3µs/call | ||||
| 125 | 200952 | 165ms | my $m = shift; | ||
| 126 | my ($n, $f, $a, $i) = @$m; | ||||
| 127 | my $p = $i->{ $_[ 0 ] }; | ||||
| 128 | defined $p ? ( ref $p eq 'ARRAY' ? @$p : $p ) : ( ); | ||||
| 129 | } | ||||
| 130 | |||||
| 131 | sub del_path { | ||||
| 132 | my $m = shift; | ||||
| 133 | my ($n, $f, $a, $i, $s, $p) = @$m; | ||||
| 134 | if (@_ == 2) { | ||||
| 135 | @_ = sort @_ if ($f & _UNORD); | ||||
| 136 | my $e0 = shift; | ||||
| 137 | return 0 unless exists $s->{ $e0 }; | ||||
| 138 | my $e1 = shift; | ||||
| 139 | if (defined($n = $s->{ $e0 }->{ $e1 })) { | ||||
| 140 | delete $i->{ $n }; | ||||
| 141 | delete $s->{ $e0 }->{ $e1 }; | ||||
| 142 | delete $p->{ $e1 }->{ $e0 }; | ||||
| 143 | delete $s->{ $e0 } unless keys %{ $s->{ $e0 } }; | ||||
| 144 | delete $p->{ $e1 } unless keys %{ $p->{ $e1 } }; | ||||
| 145 | return 1; | ||||
| 146 | } | ||||
| 147 | } else { | ||||
| 148 | my $e = shift; | ||||
| 149 | if (defined($n = $s->{ $e })) { | ||||
| 150 | delete $i->{ $n }; | ||||
| 151 | delete $s->{ $e }; | ||||
| 152 | return 1; | ||||
| 153 | } | ||||
| 154 | } | ||||
| 155 | return 0; | ||||
| 156 | } | ||||
| 157 | |||||
| 158 | sub __successors { | ||||
| 159 | my $E = shift; | ||||
| 160 | return wantarray ? () : 0 unless defined $E->[ _s ]; | ||||
| 161 | my $g = shift; | ||||
| 162 | my $V = $g->[ _V ]; | ||||
| 163 | return wantarray ? () : 0 unless defined $V && defined $V->[ _s ]; | ||||
| 164 | # my $i = $V->_get_path_id( $_[0] ); | ||||
| 165 | my $i = | ||||
| 166 | ($V->[ _f ] & _LIGHT) ? | ||||
| 167 | $V->[ _s ]->{ $_[0] } : | ||||
| 168 | $V->_get_path_id( $_[0] ); | ||||
| 169 | return wantarray ? () : 0 unless defined $i && defined $E->[ _s ]->{ $i }; | ||||
| 170 | return keys %{ $E->[ _s ]->{ $i } }; | ||||
| 171 | } | ||||
| 172 | |||||
| 173 | sub _successors { | ||||
| 174 | my $E = shift; | ||||
| 175 | my $g = shift; | ||||
| 176 | my @s = $E->__successors($g, @_); | ||||
| 177 | if (($E->[ _f ] & _UNORD)) { | ||||
| 178 | push @s, $E->__predecessors($g, @_); | ||||
| 179 | my %s; @s{ @s } = (); | ||||
| 180 | @s = keys %s; | ||||
| 181 | } | ||||
| 182 | my $V = $g->[ _V ]; | ||||
| 183 | return wantarray ? map { $V->[ _i ]->{ $_ } } @s : @s; | ||||
| 184 | } | ||||
| 185 | |||||
| 186 | sub __predecessors { | ||||
| 187 | my $E = shift; | ||||
| 188 | return wantarray ? () : 0 unless defined $E->[ _p ]; | ||||
| 189 | my $g = shift; | ||||
| 190 | my $V = $g->[ _V ]; | ||||
| 191 | return wantarray ? () : 0 unless defined $V && defined $V->[ _s ]; | ||||
| 192 | # my $i = $V->_get_path_id( $_[0] ); | ||||
| 193 | my $i = | ||||
| 194 | ($V->[ _f ] & _LIGHT) ? | ||||
| 195 | $V->[ _s ]->{ $_[0] } : | ||||
| 196 | $V->_get_path_id( $_[0] ); | ||||
| 197 | return wantarray ? () : 0 unless defined $i && defined $E->[ _p ]->{ $i }; | ||||
| 198 | return keys %{ $E->[ _p ]->{ $i } }; | ||||
| 199 | } | ||||
| 200 | |||||
| 201 | sub _predecessors { | ||||
| 202 | my $E = shift; | ||||
| 203 | my $g = shift; | ||||
| 204 | my @p = $E->__predecessors($g, @_); | ||||
| 205 | if ($E->[ _f ] & _UNORD) { | ||||
| 206 | push @p, $E->__successors($g, @_); | ||||
| 207 | my %p; @p{ @p } = (); | ||||
| 208 | @p = keys %p; | ||||
| 209 | } | ||||
| 210 | my $V = $g->[ _V ]; | ||||
| 211 | return wantarray ? map { $V->[ _i ]->{ $_ } } @p : @p; | ||||
| 212 | } | ||||
| 213 | |||||
| 214 | # spent 13.9ms (2.11+11.8) within Graph::AdjacencyMap::Light::__attr which was called 67 times, avg 208µs/call:
# 67 times (2.11ms+11.8ms) by Graph::AdjacencyMap::_set_path_attr at line 207 of Graph/AdjacencyMap.pm, avg 208µs/call | ||||
| 215 | # Major magic takes place here: we rebless the appropriate 'light' | ||||
| 216 | # map into a more complex map and then redispatch the method. | ||||
| 217 | 536 | 1.24ms | my $m = $_[0]; | ||
| 218 | my ($n, $f, $a, $i, $s, $p, $g) = @$m; | ||||
| 219 | my ($k, $v) = each %$i; | ||||
| 220 | my @V = @{ $g->[ _V ] }; | ||||
| 221 | 67 | 3.30ms | my @E = $g->edges; # TODO: Both these (ZZZ) lines are mysteriously needed! # spent 3.30ms making 67 calls to Graph::edges, avg 49µs/call | ||
| 222 | # ZZZ: an example of failing tests is t/52_edge_attributes.t. | ||||
| 223 | 201 | 752µs | if (ref $v eq 'ARRAY') { # Edges, then. | ||
| 224 | # print "Reedging.\n"; | ||||
| 225 | 67 | 2.67ms | @E = $g->edges; # TODO: Both these (ZZZ) lines are mysteriously needed! # spent 2.67ms making 67 calls to Graph::edges, avg 40µs/call | ||
| 226 | 67 | 303µs | $g->[ _E ] = $m = Graph::AdjacencyMap::Heavy->_new($f, 2); # spent 303µs making 67 calls to Graph::AdjacencyMap::_new, avg 5µs/call | ||
| 227 | 67 | 5.56ms | $g->add_edges( @E ); # spent 5.56ms making 67 calls to Graph::add_edges, avg 83µs/call | ||
| 228 | } else { | ||||
| 229 | # print "Revertexing.\n"; | ||||
| 230 | $m = Graph::AdjacencyMap::Vertex->_new(($f & ~_LIGHT), 1); | ||||
| 231 | $m->[ _n ] = $V[ _n ]; | ||||
| 232 | $m->[ _i ] = $V[ _i ]; | ||||
| 233 | $m->[ _s ] = $V[ _s ]; | ||||
| 234 | $m->[ _p ] = $V[ _p ]; | ||||
| 235 | $g->[ _V ] = $m; | ||||
| 236 | } | ||||
| 237 | $_[0] = $m; | ||||
| 238 | 67 | 641µs | goto &{ ref($m) . "::__attr" }; # Redispatch. # spent 641µs making 67 calls to Graph::AdjacencyMap::Heavy::__attr, avg 10µs/call | ||
| 239 | } | ||||
| 240 | |||||
| 241 | sub _is_COUNT () { 0 } | ||||
| 242 | sub _is_MULTI () { 0 } | ||||
| 243 | sub _is_HYPER () { 0 } | ||||
| 244 | sub _is_UNIQ () { 0 } | ||||
| 245 | sub _is_REF () { 0 } | ||||
| 246 | |||||
| 247 | 1 | 2µs | 1; | ||
# spent 9.81ms within Graph::AdjacencyMap::Light::CORE:sort which was called 9977 times, avg 984ns/call:
# 9977 times (9.81ms+0s) by Graph::AdjacencyMap::Light::set_path at line 38, avg 984ns/call | |||||
# spent 96µs within Graph::AdjacencyMap::Light::_is_COUNT which was called 179 times, avg 536ns/call:
# 141 times (77µs+0s) by Graph::countedged at line 337 of Graph.pm, avg 544ns/call
# 38 times (19µs+0s) by Graph::countvertexed at line 328 of Graph.pm, avg 508ns/call | |||||
# spent 95µs within Graph::AdjacencyMap::Light::_is_HYPER which was called 76 times, avg 1µs/call:
# 76 times (95µs+0s) by Graph::vertices05 at line 412 of Graph.pm, avg 1µs/call | |||||
# spent 15.8ms within Graph::AdjacencyMap::Light::_is_MULTI which was called 35195 times, avg 449ns/call:
# 24972 times (11.2ms+0s) by Graph::multivertexed at line 329 of Graph.pm, avg 447ns/call
# 10223 times (4.67ms+0s) by Graph::multiedged at line 338 of Graph.pm, avg 457ns/call |