Profile of Class/XSAccessor.pm

← Index
NYTProf Performance Profile «line view»
For t/optimization.t
Run on Thu Jan 8 22:47:42 2015
Reported on Thu Jan 8 22:48:05 2015

Filename | /home/ss5/perl5/perlbrew/perls/tapper-perl/lib/site_perl/5.16.3/x86_64-linux/Class/XSAccessor.pm
Statements | Executed 277 statements in 1.65ms

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
1 | 1 | 1 | 363µs | 513µs | Class::XSAccessor::::BEGIN@6Class::XSAccessor::BEGIN@6
4 | 4 | 4 | 242µs | 640µs | Class::XSAccessor::::importClass::XSAccessor::import
9 | 2 | 1 | 163µs | 349µs | Class::XSAccessor::::_generate_methodClass::XSAccessor::_generate_method
7 | 1 | 1 | 53µs | 53µs | Class::XSAccessor::::newxs_accessorClass::XSAccessor::newxs_accessor (xsub)
24 | 6 | 1 | 49µs | 49µs | Class::XSAccessor::::_make_hashClass::XSAccessor::_make_hash
1 | 1 | 1 | 17µs | 17µs | Class::XSAccessor::::BEGIN@2Class::XSAccessor::BEGIN@2
1 | 1 | 1 | 12µs | 24µs | Class::XSAccessor::::BEGIN@80Class::XSAccessor::BEGIN@80
1 | 1 | 1 | 10µs | 14µs | Class::XSAccessor::::BEGIN@4Class::XSAccessor::BEGIN@4
1 | 1 | 1 | 9µs | 37µs | Class::XSAccessor::::BEGIN@5Class::XSAccessor::BEGIN@5
1 | 1 | 1 | 9µs | 23µs | Class::XSAccessor::::BEGIN@3Class::XSAccessor::BEGIN@3
2 | 1 | 1 | 8µs | 8µs | Class::XSAccessor::::newxs_constructorClass::XSAccessor::newxs_constructor (xsub)
1 | 1 | 1 | 7µs | 7µs | Class::XSAccessor::::BEGIN@7Class::XSAccessor::BEGIN@7
9 | 1 | 1 | 7µs | 7µs | Class::XSAccessor::::CORE:matchClass::XSAccessor::CORE:match (opcode)
1 | 1 | 1 | 2µs | 2µs | Class::XSAccessor::::ENDClass::XSAccessor::END (xsub)

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

Line | State ments | Time on line | Calls | Time in subs | Code
--- | --- | --- | --- | --- | ---
1 |  |  |  |  | package Class::XSAccessor;
2 | 2 | 49µs | 1 | 17µs | # spent 17µs within Class::XSAccessor::BEGIN@2 which was called: # once (17µs+0s) by Class::XSAccessor::Array::BEGIN@6 at line 2 use 5.008; # spent 17µs making 1 call to Class::XSAccessor::BEGIN@2
3 | 2 | 24µs | 2 | 37µs | # spent 23µs (9+14) within Class::XSAccessor::BEGIN@3 which was called: # once (9µs+14µs) by Class::XSAccessor::Array::BEGIN@6 at line 3 use strict; # spent 23µs making 1 call to Class::XSAccessor::BEGIN@3 # spent 14µs making 1 call to strict::import
4 | 2 | 25µs | 2 | 19µs | # spent 14µs (10+5) within Class::XSAccessor::BEGIN@4 which was called: # once (10µs+5µs) by Class::XSAccessor::Array::BEGIN@6 at line 4 use warnings; # spent 14µs making 1 call to Class::XSAccessor::BEGIN@4 # spent 5µs making 1 call to warnings::import
5 | 2 | 31µs | 2 | 65µs | # spent 37µs (9+28) within Class::XSAccessor::BEGIN@5 which was called: # once (9µs+28µs) by Class::XSAccessor::Array::BEGIN@6 at line 5 use Carp qw/croak/; # spent 37µs making 1 call to Class::XSAccessor::BEGIN@5 # spent 28µs making 1 call to Exporter::import
6 | 2 | 93µs | 1 | 513µs | # spent 513µs (363+151) within Class::XSAccessor::BEGIN@6 which was called: # once (363µs+151µs) by Class::XSAccessor::Array::BEGIN@6 at line 6 use Class::XSAccessor::Heavy; # spent 513µs making 1 call to Class::XSAccessor::BEGIN@6
7 | 2 | 413µs | 1 | 7µs | # spent 7µs within Class::XSAccessor::BEGIN@7 which was called: # once (7µs+0s) by Class::XSAccessor::Array::BEGIN@6 at line 7 use XSLoader; # spent 7µs making 1 call to Class::XSAccessor::BEGIN@7
8 |  |  |  |  |
9 | 1 | 600ns |  |  | our $VERSION = '1.16';
10 |  |  |  |  |
11 | 1 | 322µs | 1 | 314µs | XSLoader::load('Class::XSAccessor', $VERSION); # spent 314µs making 1 call to XSLoader::load
12 |  |  |  |  |
13 |  |  |  |  | # spent 49µs within Class::XSAccessor::_make_hash which was called 24 times, avg 2µs/call: # 4 times (16µs+0s) by Class::XSAccessor::import at line 39, avg 4µs/call # 4 times (12µs+0s) by Class::XSAccessor::import at line 37, avg 3µs/call # 4 times (6µs+0s) by Class::XSAccessor::import at line 38, avg 2µs/call # 4 times (6µs+0s) by Class::XSAccessor::import at line 40, avg 1µs/call # 4 times (5µs+0s) by Class::XSAccessor::import at line 41, avg 1µs/call # 4 times (5µs+0s) by Class::XSAccessor::import at line 42, avg 1µs/call sub _make_hash {
14 | 24 | 5µs |  |  | my $ref = shift;
15 |  |  |  |  |
16 | 24 | 21µs |  |  | if (ref ($ref)) {
17 |  |  |  |  | if (ref($ref) eq 'ARRAY') {
18 |  |  |  |  | $ref = { map { $_ => $_ } @$ref }
19 |  |  |  |  | }
20 |  |  |  |  | } else {
21 |  |  |  |  | $ref = { $ref, $ref };
22 |  |  |  |  | }
23 |  |  |  |  |
24 | 24 | 60µs |  |  | return $ref;
25 |  |  |  |  | }
26 |  |  |  |  |
27 |  |  |  |  | # spent 640µs (242+398) within Class::XSAccessor::import which was called 4 times, avg 160µs/call: # once (73µs+191µs) by Data::DPath::Point::BEGIN@8 at line 8 of lib/Data/DPath/Point.pm # once (69µs+112µs) by Data::DPath::Path::BEGIN@14 at line 14 of lib/Data/DPath/Path.pm # once (52µs+85µs) by Data::DPath::Attrs::BEGIN@8 at line 8 of lib/Data/DPath/Attrs.pm # once (48µs+10µs) by Class::XSAccessor::Array::BEGIN@6 at line 6 of Class/XSAccessor/Array.pm sub import {
28 | 4 | 2µs |  |  | my $own_class = shift;
29 | 4 | 6µs |  |  | my ($caller_pkg) = caller();
30 |  |  |  |  |
31 |  |  |  |  | # Support both { getters => ... } and plain getters => ...
32 | 4 | 11µs |  |  | my %opts = ref($_[0]) eq 'HASH' ? %{$_[0]} : @_;
33 |  |  |  |  |
34 | 4 | 2µs |  |  | $caller_pkg = $opts{class} if defined $opts{class};
35 |  |  |  |  |
36 |  |  |  |  | # TODO: Refactor. Move more duplicated code to ::Heavy
37 | 4 | 9µs | 4 | 12µs | my $read_subs = _make_hash($opts{getters} || {}); # spent 12µs making 4 calls to Class::XSAccessor::_make_hash, avg 3µs/call
38 | 4 | 6µs | 4 | 6µs | my $set_subs = _make_hash($opts{setters} || {}); # spent 6µs making 4 calls to Class::XSAccessor::_make_hash, avg 2µs/call
39 | 4 | 6µs | 4 | 16µs | my $acc_subs = _make_hash($opts{accessors} || {}); # spent 16µs making 4 calls to Class::XSAccessor::_make_hash, avg 4µs/call
40 | 4 | 6µs | 4 | 6µs | my $lvacc_subs = _make_hash($opts{lvalue_accessors} || {}); # spent 6µs making 4 calls to Class::XSAccessor::_make_hash, avg 1µs/call
41 | 4 | 6µs | 4 | 5µs | my $pred_subs = _make_hash($opts{predicates} || {}); # spent 5µs making 4 calls to Class::XSAccessor::_make_hash, avg 1µs/call
42 | 4 | 6µs | 4 | 5µs | my $test_subs = _make_hash($opts{__tests__} || {}); # spent 5µs making 4 calls to Class::XSAccessor::_make_hash, avg 1µs/call
43 | 4 | 5µs |  |  | my $construct_subs = $opts{constructors} || [defined($opts{constructor}) ? $opts{constructor} : ()];
44 | 4 | 2µs |  |  | my $true_subs = $opts{true} || [];
45 | 4 | 2µs |  |  | my $false_subs = $opts{false} || [];
46 |  |  |  |  |
47 | 4 | 18µs |  |  | foreach my $subtype ( ["getter", $read_subs],
48 |  |  |  |  | ["setter", $set_subs],
49 |  |  |  |  | ["accessor", $acc_subs],
50 |  |  |  |  | ["lvalue_accessor", $lvacc_subs],
51 |  |  |  |  | ["test", $test_subs],
52 |  |  |  |  | ["predicate", $pred_subs] )
53 |  |  |  |  | {
54 | 24 | 7µs |  |  | my $subs = $subtype->[1];
55 | 24 | 33µs |  |  | foreach my $subname (keys %$subs) {
56 | 7 | 5µs |  |  | my $hashkey = $subs->{$subname};
57 | 7 | 24µs | 7 | 292µs | _generate_method($caller_pkg, $subname, $hashkey, \%opts, $subtype->[0]); # spent 292µs making 7 calls to Class::XSAccessor::_generate_method, avg 42µs/call
58 |  |  |  |  | }
59 |  |  |  |  | }
60 |  |  |  |  |
61 | 4 | 32µs |  |  | foreach my $subtype ( ["constructor", $construct_subs],
62 |  |  |  |  | ["true", $true_subs],
63 |  |  |  |  | ["false", $false_subs] )
64 |  |  |  |  | {
65 | 12 | 11µs |  |  | foreach my $subname (@{$subtype->[1]}) {
66 | 2 | 5µs | 2 | 57µs | _generate_method($caller_pkg, $subname, "", \%opts, $subtype->[0]); # spent 57µs making 2 calls to Class::XSAccessor::_generate_method, avg 28µs/call
67 |  |  |  |  | }
68 |  |  |  |  | }
69 |  |  |  |  | }
70 |  |  |  |  |
71 |  |  |  |  | # spent 349µs (163+187) within Class::XSAccessor::_generate_method which was called 9 times, avg 39µs/call: # 7 times (137µs+155µs) by Class::XSAccessor::import at line 57, avg 42µs/call # 2 times (25µs+32µs) by Class::XSAccessor::import at line 66, avg 28µs/call sub _generate_method {
72 | 9 | 9µs |  |  | my ($caller_pkg, $subname, $hashkey, $opts, $type) = @_;
73 |  |  |  |  |
74 | 9 | 3µs |  |  | croak("Cannot use undef as a hash key for generating an XS $type accessor. (Sub: $subname)")
75 |  |  |  |  | if not defined $hashkey;
76 |  |  |  |  |
77 | 9 | 41µs | 9 | 7µs | $subname = "${caller_pkg}::$subname" if $subname !~ /::/; # spent 7µs making 9 calls to Class::XSAccessor::CORE:match, avg 733ns/call
78 |  |  |  |  |
79 | 9 | 25µs | 9 | 119µs | Class::XSAccessor::Heavy::check_sub_existence($subname) if not $opts->{replace}; # spent 119µs making 9 calls to Class::XSAccessor::Heavy::check_sub_existence, avg 13µs/call
80 | 2 | 170µs | 2 | 36µs | # spent 24µs (12+12) within Class::XSAccessor::BEGIN@80 which was called: # once (12µs+12µs) by Class::XSAccessor::Array::BEGIN@6 at line 80 no warnings 'redefine'; # don't warn about an explicitly requested redefine # spent 24µs making 1 call to Class::XSAccessor::BEGIN@80 # spent 12µs making 1 call to warnings::unimport
81 |  |  |  |  |
82 | 9 | 52µs | 2 | 8µs | if ($type eq 'getter') { # spent 8µs making 2 calls to Class::XSAccessor::newxs_constructor, avg 4µs/call
83 |  |  |  |  | newxs_getter($subname, $hashkey);
84 |  |  |  |  | }
85 |  |  |  |  | elsif ($type eq 'lvalue_accessor') {
86 |  |  |  |  | newxs_lvalue_accessor($subname, $hashkey);
87 |  |  |  |  | }
88 |  |  |  |  | elsif ($type eq 'setter') {
89 |  |  |  |  | newxs_setter($subname, $hashkey, $opts->{chained}||0);
90 |  |  |  |  | }
91 |  |  |  |  | elsif ($type eq 'predicate') {
92 |  |  |  |  | newxs_predicate($subname, $hashkey);
93 |  |  |  |  | }
94 |  |  |  |  | elsif ($type eq 'constructor') {
95 |  |  |  |  | newxs_constructor($subname);
96 |  |  |  |  | }
97 |  |  |  |  | elsif ($type eq 'true') {
98 |  |  |  |  | newxs_boolean($subname, 1);
99 |  |  |  |  | }
100 |  |  |  |  | elsif ($type eq 'false') {
101 |  |  |  |  | newxs_boolean($subname, 0);
102 |  |  |  |  | }
103 |  |  |  |  | elsif ($type eq 'test') {
104 |  |  |  |  | newxs_test($subname, $hashkey);
105 |  |  |  |  | }
106 |  |  |  |  | else {
107 | 7 | 99µs | 7 | 53µs | newxs_accessor($subname, $hashkey, $opts->{chained}||0); # spent 53µs making 7 calls to Class::XSAccessor::newxs_accessor, avg 8µs/call
108 |  |  |  |  | }
109 |  |  |  |  | }
110 |  |  |  |  |
111 | 1 | 4µs |  |  | 1;
112 |  |  |  |  |
113 |  |  |  |  | __END__
|  |  |  |  | # spent 7µs within Class::XSAccessor::CORE:match which was called 9 times, avg 733ns/call: # 9 times (7µs+0s) by Class::XSAccessor::_generate_method at line 77, avg 733ns/call sub Class::XSAccessor::CORE:match; # opcode
|  |  |  |  | # spent 2µs within Class::XSAccessor::END which was called: # once (2µs+0s) by main::RUNTIME at line 0 of t/optimization.t sub Class::XSAccessor::END; # xsub
|  |  |  |  | # spent 53µs within Class::XSAccessor::newxs_accessor which was called 7 times, avg 8µs/call: # 7 times (53µs+0s) by Class::XSAccessor::_generate_method at line 107, avg 8µs/call sub Class::XSAccessor::newxs_accessor; # xsub
|  |  |  |  | # spent 8µs within Class::XSAccessor::newxs_constructor which was called 2 times, avg 4µs/call: # 2 times (8µs+0s) by Class::XSAccessor::_generate_method at line 82, avg 4µs/call sub Class::XSAccessor::newxs_constructor; # xsub