← Index
NYTProf Performance Profile   « line view »
For index.cgi
  Run on Sat May 9 17:18:47 2020
Reported on Sat May 9 17:19:07 2020

Filename/usr/local/share/perl/5.18.2/Sub/Quote.pm
StatementsExecuted 281 statements in 10.9ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1112.82ms3.59msSub::Quote::::BEGIN@10Sub::Quote::BEGIN@10
2111.66ms1.78msSub::Quote::::_clean_evalSub::Quote::_clean_eval
111999µs1.31msSub::Quote::::BEGIN@7Sub::Quote::BEGIN@7
8293300µs456µsSub::Quote::::quotifySub::Quote::quotify
211163µs279µsSub::Quote::::capture_unrollSub::Quote::capture_unroll
211161µs252µsSub::Quote::::quote_subSub::Quote::quote_sub
211143µs2.22msSub::Quote::::unquote_subSub::Quote::unquote_sub
121130µs30µsSub::Quote::::quoted_from_subSub::Quote::quoted_from_sub
182128µs28µsSub::Quote::::CORE:matchSub::Quote::CORE:match (opcode)
11115µs47µsSub::Quote::::BEGIN@5Sub::Quote::BEGIN@5
21112µs12µsSub::Quote::::CORE:substSub::Quote::CORE:subst (opcode)
11111µs28µsSub::Quote::::BEGIN@162Sub::Quote::BEGIN@162
11110µs40µsSub::Quote::::BEGIN@8Sub::Quote::BEGIN@8
1119µs17µsSub::Quote::::BEGIN@9Sub::Quote::BEGIN@9
1117µs7µsSub::Quote::::BEGIN@11Sub::Quote::BEGIN@11
0000s0sSub::Quote::::CLONESub::Quote::CLONE
0000s0sSub::Quote::::__ANON__[:107]Sub::Quote::__ANON__[:107]
0000s0sSub::Quote::::inlinifySub::Quote::inlinify
0000s0sSub::Quote::::qsubSub::Quote::qsub
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Sub::Quote;
2
32470µs
# spent 1.78ms (1.66+119µs) within Sub::Quote::_clean_eval which was called 2 times, avg 892µs/call: # 2 times (1.66ms+119µs) by Sub::Quote::unquote_sub at line 167, avg 892µs/call
sub _clean_eval { eval $_[0] }
# spent 985µs executing statements in string eval
# includes 234µs spent executing 5 calls to 3 subs defined therein. # spent 448µs executing statements in string eval
# includes 78µs spent executing 5 calls to 3 subs defined therein.
4
5236µs278µs
# spent 47µs (15+32) within Sub::Quote::BEGIN@5 which was called: # once (15µs+32µs) by Method::Generate::Constructor::BEGIN@4 at line 5
use Moo::_strictures;
# spent 47µs making 1 call to Sub::Quote::BEGIN@5 # spent 32µs making 1 call to Moo::_strictures::import
6
72117µs21.36ms
# spent 1.31ms (999µs+308µs) within Sub::Quote::BEGIN@7 which was called: # once (999µs+308µs) by Method::Generate::Constructor::BEGIN@4 at line 7
use Sub::Defer qw(defer_sub);
# spent 1.31ms making 1 call to Sub::Quote::BEGIN@7 # spent 49µs making 1 call to Exporter::import
8232µs270µs
# spent 40µs (10+30) within Sub::Quote::BEGIN@8 which was called: # once (10µs+30µs) by Method::Generate::Constructor::BEGIN@4 at line 8
use Scalar::Util qw(weaken);
# spent 40µs making 1 call to Sub::Quote::BEGIN@8 # spent 30µs making 1 call to Exporter::import
9226µs224µs
# spent 17µs (9+7) within Sub::Quote::BEGIN@9 which was called: # once (9µs+7µs) by Method::Generate::Constructor::BEGIN@4 at line 9
use Exporter qw(import);
# spent 17µs making 1 call to Sub::Quote::BEGIN@9 # spent 7µs making 1 call to Exporter::import
102173µs13.59ms
# spent 3.59ms (2.82+770µs) within Sub::Quote::BEGIN@10 which was called: # once (2.82ms+770µs) by Method::Generate::Constructor::BEGIN@4 at line 10
use B ();
# spent 3.59ms making 1 call to Sub::Quote::BEGIN@10
11
# spent 7µs within Sub::Quote::BEGIN@11 which was called: # once (7µs+0s) by Method::Generate::Constructor::BEGIN@4 at line 13
BEGIN {
1217µs *_HAVE_PERLSTRING = defined &B::perlstring ? sub(){1} : sub(){0};
1311.24ms17µs}
# spent 7µs making 1 call to Sub::Quote::BEGIN@11
14
151800nsour $VERSION = '2.001000';
16121µs$VERSION = eval $VERSION;
# spent 3µs executing statements in string eval
17
1812µsour @EXPORT = qw(quote_sub unquote_sub quoted_from_sub qsub);
191800nsour @EXPORT_OK = qw(quotify capture_unroll inlinify);
20
211300nsour %QUOTED;
22
23
# spent 456µs (300+157) within Sub::Quote::quotify which was called 82 times, avg 6µs/call: # 16 times (68µs+29µs) by Sub::Quote::capture_unroll at line 36, avg 6µs/call # 15 times (58µs+23µs) by Method::Generate::Constructor::_assign_new at line 213 of Method/Generate/Constructor.pm, avg 5µs/call # 15 times (58µs+21µs) by Method::Generate::Accessor::_generate_simple_set at line 543 of Method/Generate/Accessor.pm, avg 5µs/call # 15 times (42µs+29µs) by Method::Generate::Accessor::_generate_core_set at line 537 of Method/Generate/Accessor.pm, avg 5µs/call # 9 times (24µs+9µs) by Method::Generate::Accessor::_wrap_attr_exception at line 421 of Method/Generate/Accessor.pm, avg 4µs/call # 4 times (15µs+20µs) by Sub::Quote::quote_sub at line 88, avg 9µs/call # 3 times (10µs+4µs) by Method::Generate::Accessor::_attr_desc at line 384 of Method/Generate/Accessor.pm, avg 5µs/call # 3 times (8µs+6µs) by Method::Generate::Accessor::_wrap_attr_exception at line 420 of Method/Generate/Accessor.pm, avg 5µs/call # 2 times (16µs+17µs) by Method::Generate::Constructor::_handle_subconstructor at line 161 of Method/Generate/Constructor.pm, avg 16µs/call
sub quotify {
2482533µs82157µs ! defined $_[0] ? 'undef()'
# spent 157µs making 82 calls to B::perlstring, avg 2µs/call
25 : _HAVE_PERLSTRING ? B::perlstring($_[0])
26 : qq["\Q$_[0]\E"];
27}
28
29
# spent 279µs (163+115) within Sub::Quote::capture_unroll which was called 2 times, avg 139µs/call: # 2 times (163µs+115µs) by Sub::Quote::unquote_sub at line 143, avg 139µs/call
sub capture_unroll {
3022µs my ($from, $captures, $indent) = @_;
311662µs1619µs join(
# spent 19µs making 16 calls to Sub::Quote::CORE:match, avg 1µs/call
32 '',
33 map {
34233µs /^([\@\%\$])/
35 or die "capture key should start with \@, \% or \$: $_";
363285µs1697µs (' ' x $indent).qq{my ${_} = ${1}{${from}->{${\quotify $_}}};\n};
# spent 97µs making 16 calls to Sub::Quote::quotify, avg 6µs/call
37 } keys %$captures
38 );
39}
40
41sub inlinify {
42 my ($code, $args, $extra, $local) = @_;
43 my $do = 'do { '.($extra||'');
44 if ($code =~ s/^(\s*package\s+([a-zA-Z0-9:]+);)//) {
45 $do .= $1;
46 }
47 if ($code =~ s{
48 \A((?:\#\ BEGIN\ quote_sub\ PRELUDE\n.*?\#\ END\ quote_sub\ PRELUDE\n)?\s*)
49 (^\s*) my \s* \(([^)]+)\) \s* = \s* \@_;
50 }{}xms) {
51 my ($pre, $indent, $code_args) = ($1, $2, $3);
52 $do .= $pre;
53 if ($code_args ne $args) {
54 $do .= $indent . 'my ('.$code_args.') = ('.$args.'); ';
55 }
56 }
57 elsif ($local || $args ne '@_') {
58 $do .= ($local ? 'local ' : '').'@_ = ('.$args.'); ';
59 }
60 $do.$code.' }';
61}
62
63
# spent 252µs (161+91) within Sub::Quote::quote_sub which was called 2 times, avg 126µs/call: # 2 times (161µs+91µs) by Method::Generate::Constructor::generate_method at line 154 of Method/Generate/Constructor.pm, avg 126µs/call
sub quote_sub {
64 # HOLY DWIMMERY, BATMAN!
65 # $name => $code => \%captures => \%options
66 # $name => $code => \%captures
67 # $name => $code
68 # $code => \%captures => \%options
69 # $code
70215µs my $options =
71 (ref($_[-1]) eq 'HASH' and ref($_[-2]) eq 'HASH')
72 ? pop
73 : {};
7421µs my $captures = ref($_[-1]) eq 'HASH' ? pop : undef;
7523µs undef($captures) if $captures && !keys %$captures;
76211µs my $code = pop;
7721µs my $name = $_[0];
7822µs if ($name) {
792900ns my $subname = $name;
80229µs212µs my $package = $subname =~ s/(.*)::// ? $1 : caller;
# spent 12µs making 2 calls to Sub::Quote::CORE:subst, avg 6µs/call
8122µs $name = join '::', $package, $subname;
8225µs die "package name $package too long!"
83 if length $package > 252;
8422µs die "sub name $subname too long!"
85 if length $subname > 252;
86 }
87213µs my ($package, $hints, $bitmask, $hintshash) = (caller(0))[0,8,9,10];
88218µs435µs my $context
# spent 35µs making 4 calls to Sub::Quote::quotify, avg 9µs/call
89 ="# BEGIN quote_sub PRELUDE\n"
90 ."package $package;\n"
91 ."BEGIN {\n"
92 ." \$^H = ".quotify($hints).";\n"
93 ." \${^WARNING_BITS} = ".quotify($bitmask).";\n"
94 ." \%^H = (\n"
95 . join('', map
96 " ".quotify($_)." => ".quotify($hintshash->{$_}).",",
97 keys %$hintshash)
98 ." );\n"
99 ."}\n"
100 ."# END quote_sub PRELUDE\n";
101210µs $code = "$context$code";
1022400ns my $quoted_info;
1032500ns my $unquoted;
104 my $deferred = defer_sub +($options->{no_install} ? undef : $name) => sub {
105 $unquoted if 0;
106 unquote_sub($quoted_info->[4]);
107216µs238µs };
# spent 38µs making 2 calls to Sub::Defer::defer_sub, avg 19µs/call
10828µs $quoted_info = [ $name, $code, $captures, \$unquoted, $deferred ];
10928µs22µs weaken($quoted_info->[3]);
# spent 2µs making 2 calls to Scalar::Util::weaken, avg 1µs/call
11026µs22µs weaken($quoted_info->[4]);
# spent 2µs making 2 calls to Scalar::Util::weaken, avg 850ns/call
11127µs22µs weaken($QUOTED{$deferred} = $quoted_info);
# spent 2µs making 2 calls to Scalar::Util::weaken, avg 850ns/call
11229µs return $deferred;
113}
114
115
# spent 30µs within Sub::Quote::quoted_from_sub which was called 12 times, avg 3µs/call: # 12 times (30µs+0s) by Method::Generate::Accessor::_generate_call_code at line 456 of Method/Generate/Accessor.pm, avg 3µs/call
sub quoted_from_sub {
116124µs my ($sub) = @_;
117127.46ms my $quoted_info = $QUOTED{$sub||''} or return undef;
118 my ($name, $code, $captured, $unquoted, $deferred) = @{$quoted_info};
119 $unquoted &&= $$unquoted;
120 if (($deferred && $deferred eq $sub)
121 || ($unquoted && $unquoted eq $sub)) {
122 return [ $name, $code, $captured, $unquoted, $deferred ];
123 }
124 return undef;
125}
126
127
# spent 2.22ms (143µs+2.08) within Sub::Quote::unquote_sub which was called 2 times, avg 1.11ms/call: # 2 times (143µs+2.08ms) by Method::Generate::Constructor::__ANON__[/usr/local/share/perl/5.18.2/Method/Generate/Constructor.pm:102] at line 96 of Method/Generate/Constructor.pm, avg 1.11ms/call
sub unquote_sub {
12821µs my ($sub) = @_;
12922µs my $quoted = $QUOTED{$sub} or return undef;
13022µs my $unquoted = $quoted->[3];
13122µs unless ($unquoted && $$unquoted) {
13229µs my ($name, $code, $captures) = @$quoted;
1332800ns my $package;
134
135220µs29µs ($package, $name) = $name =~ /(.*)::(.*)/
# spent 9µs making 2 calls to Sub::Quote::CORE:match, avg 5µs/call
136 if $name;
137
138210µs my $make_sub = "{\n";
139
14028µs my %captures = $captures ? %$captures : ();
14122µs $captures{'$_UNQUOTED'} = \$unquoted;
14221µs $captures{'$_QUOTED'} = \$quoted;
14328µs2279µs $make_sub .= capture_unroll("\$_[1]", \%captures, 2);
# spent 279µs making 2 calls to Sub::Quote::capture_unroll, avg 139µs/call
144
14524µs $make_sub .= (
146 $name
147 # disable the 'variable $x will not stay shared' warning since
148 # we're not letting it escape from this scope anyway so there's
149 # nothing trying to share it
150 ? " no warnings 'closure';\n package ${package};\n sub ${name} {\n"
151 : " \$\$_UNQUOTED = sub {\n"
152 );
1532900ns $make_sub .= " (\$_QUOTED,\$_UNQUOTED) if 0;\n";
154220µs $make_sub .= $code;
15522µs $make_sub .= " }".($name ? '' : ';')."\n";
15622µs if ($name) {
157 $make_sub .= " \$\$_UNQUOTED = \\&${name}\n";
158 }
15921µs $make_sub .= "}\n1;\n";
16022µs $ENV{SUB_QUOTE_DEBUG} && warn $make_sub;
161 {
1624293µs246µs
# spent 28µs (11+18) within Sub::Quote::BEGIN@162 which was called: # once (11µs+18µs) by Method::Generate::Constructor::BEGIN@4 at line 162
no strict 'refs';
# spent 28µs making 1 call to Sub::Quote::BEGIN@162 # spent 18µs making 1 call to strict::unimport
16328µs local *{"${package}::${name}"} if $name;
1642700ns my ($success, $e);
165 {
16642µs local $@;
16726µs21.78ms $success = _clean_eval($make_sub, \%captures);
# spent 1.78ms making 2 calls to Sub::Quote::_clean_eval, avg 892µs/call
16822µs $e = $@;
169 }
17021µs unless ($success) {
171 die "Eval went very, very wrong:\n\n${make_sub}\n\n$e";
172 }
173218µs24µs weaken($QUOTED{$$unquoted} = $quoted);
# spent 4µs making 2 calls to Scalar::Util::weaken, avg 2µs/call
174 }
175 }
17629µs $$unquoted;
177}
178
179sub qsub ($) {
180 goto &quote_sub;
181}
182
183sub CLONE {
184 %QUOTED = map { defined $_ ? (
185 $_->[3] && ${$_->[3]} ? (${ $_->[3] } => $_) : (),
186 $_->[4] ? ($_->[4] => $_) : (),
187 ) : () } values %QUOTED;
188 weaken($_) for values %QUOTED;
189}
190
19114µs1;
192__END__
 
# spent 28µs within Sub::Quote::CORE:match which was called 18 times, avg 2µs/call: # 16 times (19µs+0s) by Sub::Quote::capture_unroll at line 31, avg 1µs/call # 2 times (9µs+0s) by Sub::Quote::unquote_sub at line 135, avg 5µs/call
sub Sub::Quote::CORE:match; # opcode
# spent 12µs within Sub::Quote::CORE:subst which was called 2 times, avg 6µs/call: # 2 times (12µs+0s) by Sub::Quote::quote_sub at line 80, avg 6µs/call
sub Sub::Quote::CORE:subst; # opcode