Filename | /usr/share/perl/5.18/Exporter.pm |
Statements | Executed 259 statements in 1.85ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
20 | 2 | 1 | 1.56ms | 1.66ms | as_heavy | Exporter::
10 | 10 | 8 | 1.37ms | 1.44ms | import | Exporter::
370 | 2 | 1 | 82µs | 82µs | CORE:subst (opcode) | Exporter::
10 | 6 | 6 | 36µs | 1.64ms | export_to_level | Exporter::
191 | 2 | 1 | 35µs | 35µs | CORE:match (opcode) | Exporter::
10 | 1 | 1 | 31µs | 93µs | export | Exporter::
0 | 0 | 0 | 0s | 0s | __ANON__[:64] | Exporter::
0 | 0 | 0 | 0s | 0s | export_fail | Exporter::
0 | 0 | 0 | 0s | 0s | export_ok_tags | Exporter::
0 | 0 | 0 | 0s | 0s | export_tags | Exporter::
0 | 0 | 0 | 0s | 0s | require_version | Exporter::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Exporter; | ||||
2 | |||||
3 | 1 | 8µs | require 5.006; | ||
4 | |||||
5 | # Be lean. | ||||
6 | #use strict; | ||||
7 | #no strict 'refs'; | ||||
8 | |||||
9 | 1 | 300ns | our $Debug = 0; | ||
10 | 1 | 100ns | our $ExportLevel = 0; | ||
11 | 1 | 300ns | our $Verbose ||= 0; | ||
12 | 1 | 300ns | our $VERSION = '5.68'; | ||
13 | 1 | 200ns | our (%Cache); | ||
14 | |||||
15 | sub as_heavy { | ||||
16 | 20 | 89µs | require Exporter::Heavy; | ||
17 | # Unfortunately, this does not work if the caller is aliased as *name = \&foo | ||||
18 | # Thus the need to create a lot of identical subroutines | ||||
19 | 20 | 35µs | my $c = (caller(1))[3]; | ||
20 | 20 | 92µs | 20 | 43µs | $c =~ s/.*:://; # spent 43µs making 20 calls to Exporter::CORE:subst, avg 2µs/call |
21 | 20 | 63µs | \&{"Exporter::Heavy::heavy_$c"}; | ||
22 | } | ||||
23 | |||||
24 | # spent 93µs (31+62) within Exporter::export which was called 10 times, avg 9µs/call:
# 10 times (31µs+62µs) by Exporter::Heavy::heavy_export_to_level at line 200 of Exporter/Heavy.pm, avg 9µs/call | ||||
25 | 10 | 33µs | 20 | 913µs | goto &{as_heavy()}; # spent 851µs making 10 calls to Exporter::Heavy::heavy_export, avg 85µs/call
# spent 62µs making 10 calls to Exporter::as_heavy, avg 6µs/call |
26 | } | ||||
27 | |||||
28 | # spent 1.44ms (1.37+73µs) within Exporter::import which was called 10 times, avg 144µs/call:
# once (577µs+23µs) by NetAddr::IP::UtilPolluted::BEGIN@198 at line 198 of NetAddr/IP/Util.pm
# once (432µs+31µs) by NetAddr::IP::FastNew::BEGIN@7 at line 7 of lib/NetAddr/IP/FastNew.pm
# once (160µs+10µs) by NetAddr::IP::Lite::BEGIN@9 at line 86 of NetAddr/IP/InetBase.pm
# once (36µs+2µs) by Benchmark::BEGIN@432 at line 432 of Benchmark.pm
# once (34µs+2µs) by NetAddr::IP::BEGIN@7 at line 7 of NetAddr/IP.pm
# once (31µs+1µs) by Socket::BEGIN@10 at line 10 of Socket.pm
# once (31µs+2µs) by NetAddr::IP::Lite::BEGIN@5 at line 5 of NetAddr/IP/Lite.pm
# once (30µs+1µs) by Socket6::BEGIN@213 at line 213 of Socket6.pm
# once (24µs+1µs) by NetAddr::IP::Lite::BEGIN@18 at line 239 of NetAddr/IP/Util.pm
# once (14µs+0s) by Benchmark::BEGIN@433 at line 433 of Benchmark.pm | ||||
29 | 10 | 4µs | my $pkg = shift; | ||
30 | 10 | 6µs | my $callpkg = caller($ExportLevel); | ||
31 | |||||
32 | 10 | 4µs | if ($pkg eq "Exporter" and @_ and $_[0] eq "import") { | ||
33 | *{$callpkg."::import"} = \&import; | ||||
34 | return; | ||||
35 | } | ||||
36 | |||||
37 | # We *need* to treat @{"$pkg\::EXPORT_FAIL"} since Carp uses it :-( | ||||
38 | 10 | 15µs | my $exports = \@{"$pkg\::EXPORT"}; | ||
39 | # But, avoid creating things if they don't exist, which saves a couple of | ||||
40 | # hundred bytes per package processed. | ||||
41 | 10 | 10µs | my $fail = ${$pkg . '::'}{EXPORT_FAIL} && \@{"$pkg\::EXPORT_FAIL"}; | ||
42 | 10 | 5µs | return export $pkg, $callpkg, @_ | ||
43 | if $Verbose or $Debug or $fail && @$fail > 1; | ||||
44 | 10 | 6µs | my $export_cache = ($Cache{$pkg} ||= {}); | ||
45 | 10 | 32µs | my $args = @_ or @_ = @$exports; | ||
46 | |||||
47 | 10 | 3µs | if ($args and not %$export_cache) { | ||
48 | s/^&//, $export_cache->{$_} = 1 | ||||
49 | 2 | 576µs | 350 | 39µs | foreach (@$exports, @{"$pkg\::EXPORT_OK"}); # spent 39µs making 350 calls to Exporter::CORE:subst, avg 110ns/call |
50 | } | ||||
51 | 10 | 1µs | my $heavy; | ||
52 | # Try very hard not to use {} and hence have to enter scope on the foreach | ||||
53 | # We bomb out of the loop with last as soon as heavy is set. | ||||
54 | 10 | 5µs | if ($args or $fail) { | ||
55 | ($heavy = (/\W/ or $args and not exists $export_cache->{$_} | ||||
56 | or $fail and @$fail and $_ eq $fail->[0])) and last | ||||
57 | 8 | 72µs | 22 | 12µs | foreach (@_); # spent 12µs making 22 calls to Exporter::CORE:match, avg 545ns/call |
58 | } else { | ||||
59 | ($heavy = /\W/) and last | ||||
60 | 2 | 227µs | 169 | 23µs | foreach (@_); # spent 23µs making 169 calls to Exporter::CORE:match, avg 134ns/call |
61 | } | ||||
62 | 10 | 1µs | return export $pkg, $callpkg, ($args ? @_ : ()) if $heavy; | ||
63 | local $SIG{__WARN__} = | ||||
64 | 10 | 46µs | sub {require Carp; &Carp::carp} if not $SIG{__WARN__}; | ||
65 | # shortcut for the common case of no type character | ||||
66 | 10 | 457µs | *{"$callpkg\::$_"} = \&{"$pkg\::$_"} foreach @_; | ||
67 | } | ||||
68 | |||||
69 | # Default methods | ||||
70 | |||||
71 | sub export_fail { | ||||
72 | my $self = shift; | ||||
73 | @_; | ||||
74 | } | ||||
75 | |||||
76 | # Unfortunately, caller(1)[3] "does not work" if the caller is aliased as | ||||
77 | # *name = \&foo. Thus the need to create a lot of identical subroutines | ||||
78 | # Otherwise we could have aliased them to export(). | ||||
79 | |||||
80 | # spent 1.64ms (36µs+1.60) within Exporter::export_to_level which was called 10 times, avg 164µs/call:
# 3 times (10µs+34µs) by NetAddr::IP::Util::import at line 189 of NetAddr/IP/Util.pm, avg 14µs/call
# 2 times (8µs+20µs) by NetAddr::IP::import at line 406 of NetAddr/IP.pm, avg 14µs/call
# 2 times (7µs+21µs) by NetAddr::IP::InetBase::import at line 277 of NetAddr/IP/InetBase.pm, avg 14µs/call
# once (5µs+1.51ms) by Time::HiRes::import at line 63 of Time/HiRes.pm
# once (3µs+11µs) by NetAddr::IP::Lite::import at line 1591 of NetAddr/IP/Lite.pm
# once (3µs+10µs) by Benchmark::import at line 467 of Benchmark.pm | ||||
81 | 10 | 50µs | 20 | 2.63ms | goto &{as_heavy()}; # spent 1.60ms making 10 calls to Exporter::as_heavy, avg 160µs/call
# spent 1.02ms making 10 calls to Exporter::Heavy::heavy_export_to_level, avg 102µs/call |
82 | } | ||||
83 | |||||
84 | sub export_tags { | ||||
85 | goto &{as_heavy()}; | ||||
86 | } | ||||
87 | |||||
88 | sub export_ok_tags { | ||||
89 | goto &{as_heavy()}; | ||||
90 | } | ||||
91 | |||||
92 | sub require_version { | ||||
93 | goto &{as_heavy()}; | ||||
94 | } | ||||
95 | |||||
96 | 1 | 4µs | 1; | ||
97 | __END__ | ||||
sub Exporter::CORE:match; # opcode | |||||
sub Exporter::CORE:subst; # opcode |