← 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
StatementsExecuted 277 statements in 1.65ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111363µs513µsClass::XSAccessor::::BEGIN@6Class::XSAccessor::BEGIN@6
444242µs640µsClass::XSAccessor::::importClass::XSAccessor::import
921163µs349µsClass::XSAccessor::::_generate_methodClass::XSAccessor::_generate_method
71153µs53µsClass::XSAccessor::::newxs_accessorClass::XSAccessor::newxs_accessor (xsub)
246149µs49µsClass::XSAccessor::::_make_hashClass::XSAccessor::_make_hash
11117µs17µsClass::XSAccessor::::BEGIN@2Class::XSAccessor::BEGIN@2
11112µs24µsClass::XSAccessor::::BEGIN@80Class::XSAccessor::BEGIN@80
11110µs14µsClass::XSAccessor::::BEGIN@4Class::XSAccessor::BEGIN@4
1119µs37µsClass::XSAccessor::::BEGIN@5Class::XSAccessor::BEGIN@5
1119µs23µsClass::XSAccessor::::BEGIN@3Class::XSAccessor::BEGIN@3
2118µs8µsClass::XSAccessor::::newxs_constructorClass::XSAccessor::newxs_constructor (xsub)
1117µs7µsClass::XSAccessor::::BEGIN@7Class::XSAccessor::BEGIN@7
9117µs7µsClass::XSAccessor::::CORE:matchClass::XSAccessor::CORE:match (opcode)
1112µs2µsClass::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
1package Class::XSAccessor;
2249µs117µ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
3224µs237µ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
4225µs219µ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
5231µs265µ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
6293µs1513µ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
72413µs17µ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
91600nsour $VERSION = '1.16';
10
111322µs1314µsXSLoader::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 {
14245µs my $ref = shift;
15
162421µs if (ref ($ref)) {
17 if (ref($ref) eq 'ARRAY') {
18 $ref = { map { $_ => $_ } @$ref }
19 }
20 } else {
21 $ref = { $ref, $ref };
22 }
23
242460µ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 {
2842µs my $own_class = shift;
2946µs my ($caller_pkg) = caller();
30
31 # Support both { getters => ... } and plain getters => ...
32411µs my %opts = ref($_[0]) eq 'HASH' ? %{$_[0]} : @_;
33
3442µs $caller_pkg = $opts{class} if defined $opts{class};
35
36 # TODO: Refactor. Move more duplicated code to ::Heavy
3749µs412µs my $read_subs = _make_hash($opts{getters} || {});
# spent 12µs making 4 calls to Class::XSAccessor::_make_hash, avg 3µs/call
3846µs46µs my $set_subs = _make_hash($opts{setters} || {});
# spent 6µs making 4 calls to Class::XSAccessor::_make_hash, avg 2µs/call
3946µs416µs my $acc_subs = _make_hash($opts{accessors} || {});
# spent 16µs making 4 calls to Class::XSAccessor::_make_hash, avg 4µs/call
4046µs46µs my $lvacc_subs = _make_hash($opts{lvalue_accessors} || {});
# spent 6µs making 4 calls to Class::XSAccessor::_make_hash, avg 1µs/call
4146µs45µs my $pred_subs = _make_hash($opts{predicates} || {});
# spent 5µs making 4 calls to Class::XSAccessor::_make_hash, avg 1µs/call
4246µs45µs my $test_subs = _make_hash($opts{__tests__} || {});
# spent 5µs making 4 calls to Class::XSAccessor::_make_hash, avg 1µs/call
4345µs my $construct_subs = $opts{constructors} || [defined($opts{constructor}) ? $opts{constructor} : ()];
4442µs my $true_subs = $opts{true} || [];
4542µs my $false_subs = $opts{false} || [];
46
47418µ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 {
54247µs my $subs = $subtype->[1];
552433µs foreach my $subname (keys %$subs) {
5675µs my $hashkey = $subs->{$subname};
57724µs7292µ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
61432µs foreach my $subtype ( ["constructor", $construct_subs],
62 ["true", $true_subs],
63 ["false", $false_subs] )
64 {
651211µs foreach my $subname (@{$subtype->[1]}) {
6625µs257µ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 {
7299µs my ($caller_pkg, $subname, $hashkey, $opts, $type) = @_;
73
7493µs croak("Cannot use undef as a hash key for generating an XS $type accessor. (Sub: $subname)")
75 if not defined $hashkey;
76
77941µs97µs $subname = "${caller_pkg}::$subname" if $subname !~ /::/;
# spent 7µs making 9 calls to Class::XSAccessor::CORE:match, avg 733ns/call
78
79925µs9119µ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
802170µs236µ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
82952µs28µ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 {
107799µs753µ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
11114µs1;
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