Profile of Exporter.pm

← Index
NYTProf Performance Profile «line view»
For examples/benchmark4.pl
Run on Thu Aug 28 19:01:43 2014
Reported on Thu Aug 28 19:02:42 2014

Filename | /usr/share/perl/5.18/Exporter.pm
Statements | Executed 259 statements in 1.85ms

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
20 | 2 | 1 | 1.56ms | 1.66ms | Exporter::::as_heavyExporter::as_heavy
10 | 10 | 8 | 1.37ms | 1.44ms | Exporter::::importExporter::import
370 | 2 | 1 | 82µs | 82µs | Exporter::::CORE:substExporter::CORE:subst (opcode)
10 | 6 | 6 | 36µs | 1.64ms | Exporter::::export_to_levelExporter::export_to_level
191 | 2 | 1 | 35µs | 35µs | Exporter::::CORE:matchExporter::CORE:match (opcode)
10 | 1 | 1 | 31µs | 93µs | Exporter::::exportExporter::export
0 | 0 | 0 | 0s | 0s | Exporter::::__ANON__[:64]Exporter::__ANON__[:64]
0 | 0 | 0 | 0s | 0s | Exporter::::export_failExporter::export_fail
0 | 0 | 0 | 0s | 0s | Exporter::::export_ok_tagsExporter::export_ok_tags
0 | 0 | 0 | 0s | 0s | Exporter::::export_tagsExporter::export_tags
0 | 0 | 0 | 0s | 0s | Exporter::::require_versionExporter::require_version

Call graph for these subroutines as a Graphviz dot language file.

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 |  |  |  |  | # spent 1.66ms (1.56+99µs) within Exporter::as_heavy which was called 20 times, avg 83µs/call: # 10 times (1.52ms+85µs) by Exporter::export_to_level at line 81, avg 160µs/call # 10 times (48µs+14µs) by Exporter::export at line 25, avg 6µs/call 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 sub export {
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 sub import {
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 sub export_to_level {
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__
|  |  |  |  | # spent 35µs within Exporter::CORE:match which was called 191 times, avg 182ns/call: # 169 times (23µs+0s) by Exporter::import at line 60, avg 134ns/call # 22 times (12µs+0s) by Exporter::import at line 57, avg 545ns/call sub Exporter::CORE:match; # opcode
|  |  |  |  | # spent 82µs within Exporter::CORE:subst which was called 370 times, avg 221ns/call: # 350 times (39µs+0s) by Exporter::import at line 49, avg 110ns/call # 20 times (43µs+0s) by Exporter::as_heavy at line 20, avg 2µs/call sub Exporter::CORE:subst; # opcode