← Index
NYTProf Performance Profile   « line view »
For fastest.pl
  Run on Fri Jan 31 20:48:16 2014
Reported on Fri Jan 31 20:49:41 2014

Filename/opt/perl-5.18.1/lib/site_perl/5.18.1/Typed.pm
StatementsExecuted 15000075 statements in 17.2s
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
20000002123.1s38.4sTyped::::__ANON__[:134]Typed::__ANON__[:134]
1117.65ms68.4msTyped::::BEGIN@10Typed::BEGIN@10
1113.48ms4.20msTyped::::BEGIN@11Typed::BEGIN@11
1111.23ms1.29msTyped::::BEGIN@5Typed::BEGIN@5
111358µs490µsTyped::::BEGIN@14Typed::BEGIN@14
11127µs40µsTyped::::newTyped::new
11121µs39µsTyped::::hasTyped::has
11121µs845µsTyped::::importTyped::import
11118µs18µsTyped::::process_hasTyped::process_has
11116µs32µsTyped::::BEGIN@3Typed::BEGIN@3
11111µs75µsTyped::::BEGIN@12Typed::BEGIN@12
11110µs24µsTyped::::BEGIN@148Typed::BEGIN@148
11110µs10µsTyped::::defaultTyped::default
11110µs51µsTyped::::BEGIN@8Typed::BEGIN@8
11110µs23µsTyped::::BEGIN@33Typed::BEGIN@33
11110µs23µsTyped::::BEGIN@78Typed::BEGIN@78
1118µs30µsTyped::::BEGIN@4Typed::BEGIN@4
1115µs5µsTyped::::BEGIN@7Typed::BEGIN@7
0000s0sTyped::::asTyped::as
0000s0sTyped::::fromTyped::from
0000s0sTyped::::subtypeTyped::subtype
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Typed;
2
3235µs249µs
# spent 32µs (16+16) within Typed::BEGIN@3 which was called: # once (16µs+16µs) by Foo::Typed::BEGIN@103 at line 3
use strict;
# spent 32µs making 1 call to Typed::BEGIN@3 # spent 16µs making 1 call to strict::import
4233µs250µs
# spent 30µs (8+21) within Typed::BEGIN@4 which was called: # once (8µs+21µs) by Foo::Typed::BEGIN@103 at line 4
use warnings FATAL => 'all';
# spent 30µs making 1 call to Typed::BEGIN@4 # spent 21µs making 1 call to warnings::import
521.22ms21.34ms
# spent 1.29ms (1.23+56µs) within Typed::BEGIN@5 which was called: # once (1.23ms+56µs) by Foo::Typed::BEGIN@103 at line 5
use feature qw(:5.10);
# spent 1.29ms making 1 call to Typed::BEGIN@5 # spent 56µs making 1 call to feature::import
6
7239µs15µs
# spent 5µs within Typed::BEGIN@7 which was called: # once (5µs+0s) by Foo::Typed::BEGIN@103 at line 7
use Carp qw();
# spent 5µs making 1 call to Typed::BEGIN@7
8245µs292µs
# spent 51µs (10+41) within Typed::BEGIN@8 which was called: # once (10µs+41µs) by Foo::Typed::BEGIN@103 at line 8
use Scalar::Util qw(blessed);
# spent 51µs making 1 call to Typed::BEGIN@8 # spent 41µs making 1 call to Exporter::import
9
102171µs271.3ms
# spent 68.4ms (7.65+60.7) within Typed::BEGIN@10 which was called: # once (7.65ms+60.7ms) by Foo::Typed::BEGIN@103 at line 10
use Types::Standard "-types";
# spent 68.4ms making 1 call to Typed::BEGIN@10 # spent 2.89ms making 1 call to Exporter::Tiny::import
112138µs14.20ms
# spent 4.20ms (3.48+718µs) within Typed::BEGIN@11 which was called: # once (3.48ms+718µs) by Foo::Typed::BEGIN@103 at line 11
use Type::Utils qw();
# spent 4.20ms making 1 call to Typed::BEGIN@11
12239µs2140µs
# spent 75µs (11+64) within Typed::BEGIN@12 which was called: # once (11µs+64µs) by Foo::Typed::BEGIN@103 at line 12
use Exporter::Tiny;
# spent 75µs making 1 call to Typed::BEGIN@12 # spent 64µs making 1 call to Exporter::Tiny::import
13
142287µs2528µs
# spent 490µs (358+131) within Typed::BEGIN@14 which was called: # once (358µs+131µs) by Foo::Typed::BEGIN@103 at line 14
use parent qw(Exporter::Tiny);
# spent 490µs making 1 call to Typed::BEGIN@14 # spent 39µs making 1 call to parent::import
15
1612µsour @EXPORT = qw(has new as from subtype);
1711µsour @TINY_UTILS = qw(message where inline_as declare coerce);
18
191300nsour $VERSION = '0.09';
20
21
# spent 845µs (21+824) within Typed::import which was called: # once (21µs+824µs) by Foo::Typed::BEGIN@103 at line 103 of fastest.pl
sub import {
2218µs1361µs shift->SUPER::import({ into => scalar(caller(0)) }, @EXPORT );
# spent 361µs making 1 call to Exporter::Tiny::import
2318µs1463µs Type::Utils->import({ into => scalar(caller(0)) }, @TINY_UTILS );
# spent 463µs making 1 call to Exporter::Tiny::import
24}
25
26
# spent 40µs (27+13) within Typed::new which was called: # once (27µs+13µs) by main::RUNTIME at line 106 of fastest.pl
sub new {
271600ns my $self = shift;
28
291700ns my $class = ref($self) || $self;
3011µs my $blessed = bless({}, $class);
31
321400ns my $meta_pkg = __PACKAGE__;
334384µs237µs
# spent 23µs (10+14) within Typed::BEGIN@33 which was called: # once (10µs+14µs) by Foo::Typed::BEGIN@103 at line 33
my $meta = do { no strict 'refs'; \%{"${meta_pkg}::meta"}; };
# spent 23µs making 1 call to Typed::BEGIN@33 # spent 14µs making 1 call to strict::unimport
34
3511µs if ($meta && $$meta{$class}) {
361600ns my $has = $$meta{$class};
3712µs foreach my $name (keys %{ $has }) {
381500ns my $opts = $$meta{$class}{$name};
39
4015µs110µs __PACKAGE__->default($blessed, $class, $name, $opts, $$opts{lazy});
# spent 10µs making 1 call to Typed::default
41 }
42 }
43
441700ns my %user_vals = @_;
4511µs foreach my $k (keys %user_vals) {
46 $blessed->{$k} = $user_vals{$k}; # TODO: Use the attribute method.
47 }
48
4917µs13µs my $build = $blessed->can("BUILD");
# spent 3µs making 1 call to UNIVERSAL::can
501200ns if ($build) {
51 $build->($blessed);
52 }
53
5414µs return($blessed);
55}
56
57
# spent 10µs within Typed::default which was called: # once (10µs+0s) by Typed::new at line 40
sub default {
581300ns my $meta_pkg = shift;
591300ns my $self = shift;
601400ns my $package = shift;
611200ns my $name = shift;
621200ns my $opts = shift;
631700ns my $lazy = shift;
64
651200ns my $default;
661500ns unless ($lazy) {
671400ns if ($$opts{default}) {
68 my $type = ref($$opts{default});
69 if ($type && "CODE" eq $type) {
70 $default = $$opts{default}->();
71 }
72 else {
73 $default = $$opts{default};
74 }
75 }
76
771500ns if ($$opts{builder}) {
782581µs237µs
# spent 23µs (10+14) within Typed::BEGIN@78 which was called: # once (10µs+14µs) by Foo::Typed::BEGIN@103 at line 78
my $builder = do { no strict 'refs'; \&{"${package}::$$opts{builder}"}; };
# spent 23µs making 1 call to Typed::BEGIN@78 # spent 14µs making 1 call to strict::unimport
79
80 if ($builder) {
81 $default = $builder->($self);
82 }
83 }
84
8513µs $self->{$name} = $default; # TODO: Use the attribute method.
86 }
87
8814µs return($default);
89}
90
91# Yes, we use a global cache for metadata
921400nsour %meta = (
93);
94
95
# spent 18µs within Typed::process_has which was called: # once (18µs+0s) by Typed::has at line 146
sub process_has {
961400ns my $self = shift;
971400ns my $name = shift;
981300ns my $package = shift;
99
10011µs my $isa = $meta{$package}{$name}{isa};
101
1021900ns my $is = $meta{$package}{$name}{is};
1031900ns my $writable = $is && "rw" eq $is;
1041800ns my $opts = $meta{$package}{$name};
105
106
# spent 38.4s (23.1+15.3) within Typed::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Typed.pm:134] which was called 2000000 times, avg 19µs/call: # 1000000 times (21.3s+15.3s) by main::typed at line 108 of fastest.pl, avg 37µs/call # 1000000 times (1.74s+0s) by main::typed at line 109 of fastest.pl, avg 2µs/call
my $attribute = sub {
1072000000482ms if (!exists $_[0]->{$name}) {
108 __PACKAGE__->default($_[0], $package, $name, $opts, 0);
109 }
110
111 # Do we set the value
1122000000565ms if (1 == $#_) {
1131000000214ms if ($writable) {
1141000000105ms return($_[0]->{$name} = undef) if !defined $_[1];
115
1161000000209ms if ($isa) {
11710000003.72s1000000761ms my $package = blessed($_[0]);
# spent 761ms making 1000000 calls to Scalar::Util::blessed, avg 761ns/call
11810000002.37s20000009.37s my $type = Types::Standard->get_type($isa) || $meta{subtype}{$package}{$isa};
# spent 8.39s making 1000000 calls to Type::Library::get_type, avg 8µs/call # spent 985ms making 1000000 calls to Type::Tiny::__ANON__[Type/Tiny.pm:32], avg 985ns/call
119
12010000001.27s1000000706ms if ($type) {
# spent 706ms making 1000000 calls to Type::Tiny::__ANON__[Type/Tiny.pm:32], avg 706ns/call
12110000001.13s10000004.50s my $msg = $type->validate($_[1]);
# spent 4.50s making 1000000 calls to Type::Tiny::validate, avg 4µs/call
1221000000208ms Carp::croak($msg) if $msg;
123 }
124 }
125
1261000000428ms $_[0]->{$name} = $_[1];
127 }
128 else {
129 Carp::croak("Attempt to modify read-only attribute: $name");
130 }
131 }
132
13320000006.52s return($_[0]->{$name});
134110µs };
135
13615µs return($attribute);
137}
138
139
# spent 39µs (21+18) within Typed::has which was called: # once (21µs+18µs) by main::RUNTIME at line 104 of fastest.pl
sub has {
1401600ns my $name = shift;
14112µs my %opts = @_;
14211µs my $package = caller;
143
14412µs $meta{$package}{$name} = \%opts;
145
14614µs118µs my $attribute = __PACKAGE__->process_has($name, $package);
# spent 18µs making 1 call to Typed::process_has
147
1484328µs238µs
# spent 24µs (10+14) within Typed::BEGIN@148 which was called: # once (10µs+14µs) by Foo::Typed::BEGIN@103 at line 148
{ no strict 'refs'; *{"${package}::$name"} = $attribute; }
# spent 24µs making 1 call to Typed::BEGIN@148 # spent 14µs making 1 call to strict::unimport
149}
150
151sub as (@) {
152 unless (blessed($_[0])) {
153 my $type = shift(@_);
154 unshift(@_, __PACKAGE__->$type);
155 }
156
157 Type::Utils::as(@_);
158}
159
160sub from (@)
161{
162 unless (blessed($_[0])) {
163 my $type = shift(@_);
164 unshift(@_, __PACKAGE__->$type);
165 }
166
167 Type::Utils::from(@_);
168}
169
170sub subtype
171{
172 my $subtype = Type::Utils::subtype(@_);
173 my $package = caller;
174 my $name = $_[0];
175 $meta{subtype}{$package}{$name} = $subtype;
176}
177
17818µs1;
179
180__END__