Filename | /usr/local/share/perl/5.18.2/Sub/Defer.pm |
Statements | Executed 80 statements in 1.15ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
4 | 2 | 2 | 80µs | 148µs | defer_sub | Sub::Defer::
3 | 2 | 2 | 50µs | 12.3ms | undefer_sub | Sub::Defer::
1 | 1 | 1 | 23µs | 90µs | BEGIN@6 | Sub::Defer::
1 | 1 | 1 | 13µs | 39µs | BEGIN@3 | Sub::Defer::
1 | 1 | 1 | 12µs | 26µs | BEGIN@27 | Sub::Defer::
2 | 1 | 1 | 11µs | 11µs | defer_info | Sub::Defer::
1 | 1 | 1 | 10µs | 18µs | BEGIN@4 | Sub::Defer::
1 | 1 | 1 | 10µs | 84µs | BEGIN@5 | Sub::Defer::
0 | 0 | 0 | 0s | 0s | CLONE | Sub::Defer::
0 | 0 | 0 | 0s | 0s | __ANON__[:68] | Sub::Defer::
0 | 0 | 0 | 0s | 0s | undefer_all | Sub::Defer::
0 | 0 | 0 | 0s | 0s | undefer_package | Sub::Defer::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Sub::Defer; | ||||
2 | |||||
3 | 2 | 34µs | 2 | 66µs | # spent 39µs (13+27) within Sub::Defer::BEGIN@3 which was called:
# once (13µs+27µs) by Sub::Quote::BEGIN@7 at line 3 # spent 39µs making 1 call to Sub::Defer::BEGIN@3
# spent 27µs making 1 call to Moo::_strictures::import |
4 | 2 | 37µs | 2 | 27µs | # spent 18µs (10+8) within Sub::Defer::BEGIN@4 which was called:
# once (10µs+8µs) by Sub::Quote::BEGIN@7 at line 4 # spent 18µs making 1 call to Sub::Defer::BEGIN@4
# spent 8µs making 1 call to Exporter::import |
5 | 2 | 36µs | 2 | 158µs | # spent 84µs (10+74) within Sub::Defer::BEGIN@5 which was called:
# once (10µs+74µs) by Sub::Quote::BEGIN@7 at line 5 # spent 84µs making 1 call to Sub::Defer::BEGIN@5
# spent 74µs making 1 call to Exporter::import |
6 | 2 | 202µs | 2 | 158µs | # spent 90µs (23+68) within Sub::Defer::BEGIN@6 which was called:
# once (23µs+68µs) by Sub::Quote::BEGIN@7 at line 6 # spent 90µs making 1 call to Sub::Defer::BEGIN@6
# spent 68µs making 1 call to Exporter::import |
7 | |||||
8 | 1 | 900ns | our $VERSION = '2.001000'; | ||
9 | 1 | 16µs | $VERSION = eval $VERSION; # spent 3µs executing statements in string eval | ||
10 | |||||
11 | 1 | 2µs | our @EXPORT = qw(defer_sub undefer_sub undefer_all); | ||
12 | 1 | 500ns | our @EXPORT_OK = qw(undefer_package); | ||
13 | |||||
14 | 1 | 300ns | our %DEFERRED; | ||
15 | |||||
16 | # spent 12.3ms (50µs+12.3) within Sub::Defer::undefer_sub which was called 3 times, avg 4.11ms/call:
# 2 times (46µs+12.3ms) by Method::Generate::Constructor::new or String::Markov::new at line 66, avg 6.16ms/call
# once (4µs+0s) by Moo::_Utils::_install_modifier at line 45 of Moo/_Utils.pm | ||||
17 | 3 | 2µs | my ($deferred) = @_; | ||
18 | my ($target, $maker, $undeferred_ref) = @{ | ||||
19 | 3 | 10µs | $DEFERRED{$deferred}||return $deferred | ||
20 | }; | ||||
21 | return ${$undeferred_ref} | ||||
22 | 2 | 1µs | if ${$undeferred_ref}; | ||
23 | 2 | 7µs | 2 | 12.3ms | ${$undeferred_ref} = my $made = $maker->(); # spent 12.3ms making 2 calls to Method::Generate::Constructor::__ANON__[Method/Generate/Constructor.pm:102], avg 6.14ms/call |
24 | |||||
25 | # make sure the method slot has not changed since deferral time | ||||
26 | 2 | 9µs | 2 | 7µs | if (defined($target) && $deferred eq *{_getglob($target)}{CODE}||'') { # spent 7µs making 2 calls to Moo::_Utils::_getglob, avg 3µs/call |
27 | 2 | 629µs | 2 | 41µs | # spent 26µs (12+14) within Sub::Defer::BEGIN@27 which was called:
# once (12µs+14µs) by Sub::Quote::BEGIN@7 at line 27 # spent 26µs making 1 call to Sub::Defer::BEGIN@27
# spent 14µs making 1 call to warnings::unimport |
28 | |||||
29 | # I believe $maker already evals with the right package/name, so that | ||||
30 | # _install_coderef calls are not necessary --ribasushi | ||||
31 | 2 | 5µs | 2 | 3µs | *{_getglob($target)} = $made; # spent 3µs making 2 calls to Moo::_Utils::_getglob, avg 1µs/call |
32 | } | ||||
33 | 2 | 3µs | $DEFERRED{$made} = $DEFERRED{$deferred}; | ||
34 | 2 | 1µs | weaken $DEFERRED{$made} | ||
35 | unless $target; | ||||
36 | |||||
37 | 2 | 17µs | return $made; | ||
38 | } | ||||
39 | |||||
40 | sub undefer_all { | ||||
41 | undefer_sub($_) for keys %DEFERRED; | ||||
42 | return; | ||||
43 | } | ||||
44 | |||||
45 | sub undefer_package { | ||||
46 | my $package = shift; | ||||
47 | undefer_sub($_) | ||||
48 | for grep { | ||||
49 | my $name = $DEFERRED{$_} && $DEFERRED{$_}[0]; | ||||
50 | $name && $name =~ /^${package}::[^:]+$/ | ||||
51 | } keys %DEFERRED; | ||||
52 | return; | ||||
53 | } | ||||
54 | |||||
55 | # spent 11µs within Sub::Defer::defer_info which was called 2 times, avg 5µs/call:
# 2 times (11µs+0s) by Moo::_accessor_maker_for at line 132 of Moo.pm, avg 5µs/call | ||||
56 | 2 | 1µs | my ($deferred) = @_; | ||
57 | 2 | 13µs | my $info = $DEFERRED{$deferred||''} or return undef; | ||
58 | [ @$info ]; | ||||
59 | } | ||||
60 | |||||
61 | # spent 148µs (80+69) within Sub::Defer::defer_sub which was called 4 times, avg 37µs/call:
# 2 times (47µs+63µs) by Method::Generate::Constructor::install_delayed at line 102 of Method/Generate/Constructor.pm, avg 55µs/call
# 2 times (32µs+6µs) by Sub::Quote::quote_sub at line 107 of Sub/Quote.pm, avg 19µs/call | ||||
62 | 4 | 3µs | my ($target, $maker) = @_; | ||
63 | 4 | 1µs | my $undeferred; | ||
64 | 4 | 900ns | my $deferred_info; | ||
65 | my $deferred = sub { | ||||
66 | 2 | 6µs | 2 | 12.3ms | $undeferred ||= undefer_sub($deferred_info->[3]); # spent 12.3ms making 2 calls to Sub::Defer::undefer_sub, avg 6.16ms/call |
67 | 2 | 18µs | 2 | 162µs | goto &$undeferred; # spent 147µs making 1 call to String::Markov::new
# spent 14µs making 1 call to Method::Generate::Constructor::new |
68 | 4 | 11µs | }; | ||
69 | 4 | 5µs | $deferred_info = [ $target, $maker, \$undeferred, $deferred ]; | ||
70 | 4 | 31µs | 4 | 10µs | weaken($deferred_info->[3]); # spent 10µs making 4 calls to Scalar::Util::weaken, avg 3µs/call |
71 | 4 | 22µs | 4 | 4µs | weaken($DEFERRED{$deferred} = $deferred_info); # spent 4µs making 4 calls to Scalar::Util::weaken, avg 1µs/call |
72 | 4 | 8µs | 2 | 54µs | _install_coderef($target => $deferred) if defined $target; # spent 54µs making 2 calls to Moo::_Utils::_install_coderef, avg 27µs/call |
73 | 4 | 15µs | return $deferred; | ||
74 | } | ||||
75 | |||||
76 | sub CLONE { | ||||
77 | %DEFERRED = map { defined $_ && $_->[3] ? ($_->[3] => $_) : () } values %DEFERRED; | ||||
78 | foreach my $info (values %DEFERRED) { | ||||
79 | weaken($info) | ||||
80 | unless $info->[0] && ${$info->[2]}; | ||||
81 | } | ||||
82 | } | ||||
83 | |||||
84 | 1 | 4µs | 1; | ||
85 | __END__ |