← Index
NYTProf Performance Profile   « line view »
For bin/benchmark-perlformance
  Run on Fri Apr 17 15:31:48 2015
Reported on Fri Apr 17 15:32:02 2015

Filename/home/ss5/perl5/perlbrew/perls/tapper-perl/lib/site_perl/5.16.3/Iterator.pm
StatementsExecuted 427 statements in 1.48ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111794µs6.91msIterator::::BEGIN@22 Iterator::BEGIN@22
2643407µs4.64msIterator::::value Iterator::value (recurses: max depth 1, inclusive time 1.52ms)
811153µs1.39msIterator::::_initialize Iterator::_initialize
84271µs71µsIterator::::DESTROY Iterator::DESTROY (recurses: max depth 1, inclusive time 19µs)
82158µs1.45msIterator::::new Iterator::new
82148µs3.83msIterator::::is_done Iterator::is_done
154137µs37µsIterator::::isnt_exhausted Iterator::isnt_exhausted
171132µs32µsIterator::::is_exhausted Iterator::is_exhausted
11110µs19µsIterator::Util::::BEGIN@15 Iterator::Util::BEGIN@15
1117µs10µsIterator::Util::::BEGIN@16 Iterator::Util::BEGIN@16
1113µs3µsIterator::::BEGIN@69 Iterator::BEGIN@69
0000s0sIterator::X::Internal_Error::::locationIterator::X::Internal_Error::location
0000s0sIterator::X::::full_message Iterator::X::full_message
0000s0sIterator::X::::location Iterator::X::location
0000s0sIterator::::__ANON__[:78] Iterator::__ANON__[:78]
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1=for gpg
2-----BEGIN PGP SIGNED MESSAGE-----
3Hash: SHA1
4
5=head1 NAME
6
7Iterator - A general-purpose iterator class.
8
9=head1 VERSION
10
11This documentation describes version 0.03 of Iterator.pm, October 10, 2005.
12
13=cut
14
15218µs229µs
# spent 19µs (10+9) within Iterator::Util::BEGIN@15 which was called: # once (10µs+9µs) by Iterator::Util::BEGIN@28 at line 15
use strict;
# spent 19µs making 1 call to Iterator::Util::BEGIN@15 # spent 9µs making 1 call to strict::import
16270µs213µs
# spent 10µs (7+3) within Iterator::Util::BEGIN@16 which was called: # once (7µs+3µs) by Iterator::Util::BEGIN@28 at line 16
use warnings;
# spent 10µs making 1 call to Iterator::Util::BEGIN@16 # spent 3µs making 1 call to warnings::import
17package Iterator;
181500nsour $VERSION = '0.03';
19
20# Declare exception classes
21use Exception::Class
22
# spent 6.91ms (794µs+6.12) within Iterator::BEGIN@22 which was called: # once (794µs+6.12ms) by Iterator::Util::BEGIN@28 at line 65
(
23112µs11.28ms 'Iterator::X' =>
# spent 1.28ms making 1 call to Exception::Class::import
24 {
25 description => 'Generic Iterator exception',
26 },
27 'Iterator::X::Parameter_Error' =>
28 {
29 isa => 'Iterator::X',
30 description => 'Iterator method parameter error',
31 },
32 'Iterator::X::OptionError' =>
33 {
34 isa => 'Iterator::X',
35 fields => 'name',
36 description => 'A bad option was passed to an iterator method or function',
37 },
38 'Iterator::X::Exhausted' =>
39 {
40 isa => 'Iterator::X',
41 description => 'Attempt to next_value () on an exhausted iterator',
42 },
43 'Iterator::X::Am_Now_Exhausted' =>
44 {
45 isa => 'Iterator::X',
46 description => 'Signals Iterator object that it is now exhausted',
47 },
48 'Iterator::X::User_Code_Error' =>
49 {
50 isa => 'Iterator::X',
51 fields => 'eval_error',
52 description => q{An exception was thrown within the user's code},
53 },
54 'Iterator::X::IO_Error' =>
55 {
56 isa => 'Iterator::X',
57 fields => 'os_error',
58 description => q{An I/O error occurred},
59 },
60 'Iterator::X::Internal_Error' =>
61 {
62 isa => 'Iterator::X',
63 description => 'An Iterator.pm internal error. Please contact author.',
64 },
651106µs16.91ms );
# spent 6.91ms making 1 call to Iterator::BEGIN@22
66
67# Class method to help caller catch exceptions
68BEGIN
69
# spent 3µs within Iterator::BEGIN@69 which was called: # once (3µs+0s) by Iterator::Util::BEGIN@28 at line 80
{
70 # Dave Rolsky added this subroutine in v1.22 of Exception::Class.
71 # Thanks, Dave!
72 # We define it here so we have the functionality in pre-1.22 versions;
73 # we make it conditional so as to avoid a warning in post-1.22 versions.
74 *Exception::Class::Base::caught = sub
75 {
76 my $class = shift;
77 return Exception::Class->caught($class);
78 }
7914µs if $Exception::Class::VERSION lt '1.22';
801458µs13µs}
# spent 3µs making 1 call to Iterator::BEGIN@69
81
82# Croak-like location of error
83sub Iterator::X::location
84{
85 my ($pkg,$file,$line);
86 my $caller_level = 0;
87 while (1)
88 {
89 ($pkg,$file,$line) = caller($caller_level++);
90 last if $pkg !~ /\A Iterator/x && $pkg !~ /\A Exception::Class/x
91 }
92 return "at $file line $line";
93}
94
95# Die-like location of error
96sub Iterator::X::Internal_Error::location
97{
98 my $self = shift;
99 return "at " . $self->file () . " line " . $self->line ()
100}
101
102# Override full_message, to report location of error in caller's code.
103sub Iterator::X::full_message
104{
105 my $self = shift;
106
107 my $msg = $self->message;
108 return $msg if substr($msg,-1,1) eq "\n";
109
110 $msg =~ s/[ \t]+\z//; # remove any trailing spaces (is this necessary?)
111 return $msg . q{ } . $self->location () . qq{\n};
112}
113
114
115## Constructor
116
117# Method name: new
118# Synopsis: $iterator = Iterator->new( $code_ref );
119# Description: Object constructor.
120# Created: 07/27/2005 by EJR
121# Parameters: $code_ref - the iterator sequence generation code.
122# Returns: New Iterator.
123# Exceptions: Iterator::X::Parameter_Error (via _initialize)
124sub new
125
# spent 1.45ms (58µs+1.39) within Iterator::new which was called 8 times, avg 181µs/call: # 4 times (21µs+1.26ms) by Iterator::Util::imap at line 52 of Iterator/Util.pm, avg 320µs/call # 4 times (37µs+128µs) by Iterator::Util::iarray at line 158 of Iterator/Util.pm, avg 41µs/call
{
12683µs my $class = shift;
12784µs my $self = \do {my $anonymous};
128812µs bless $self, $class;
129814µs81.39ms $self->_initialize(@_);
# spent 1.39ms making 8 calls to Iterator::_initialize, avg 174µs/call
130825µs return $self;
131}
132
133{ # encapsulation enclosure
134
135 # Attributes:
1362400ns my %code_for; # The sequence code (coderef) for each object.
1371100ns my %is_exhausted; # Boolean: is this object exhausted?
1381400ns my %next_value_for; # One-item lookahead buffer for each object.
139 # [if you update this list of attributes, be sure to edit DESTROY]
140
141 # Method name: _initialize
142 # Synopsis: $iterator->_initialize( $code_ref );
143 # Description: Object initializer.
144 # Created: 07/27/2005 by EJR
145 # Parameters: $code_ref - the iterator sequence generation code.
146 # Returns: Nothing.
147 # Exceptions: Iterator::X::Parameter_Error
148 # Iterator::X::User_Code_Error
149 # Notes: For internal module use only.
150 # Caches the first value of the iterator in %next_value_for.
151 sub _initialize
152
# spent 1.39ms (153µs+1.23) within Iterator::_initialize which was called 8 times, avg 174µs/call: # 8 times (153µs+1.23ms) by Iterator::new at line 129, avg 174µs/call
{
15382µs my $self = shift;
154
15583µs Iterator::X::Parameter_Error->throw(q{Too few parameters to Iterator->new()})
156 if @_ < 1;
15782µs Iterator::X::Parameter_Error->throw(q{Too many parameters to Iterator->new()})
158 if @_ > 1;
15982µs my $code = shift;
16084µs Iterator::X::Parameter_Error->throw (q{Parameter to Iterator->new() must be code reference})
161 if ref $code ne 'CODE';
162
163810µs $code_for {$self} = $code;
164
165 # Get the next (first) value for this iterator
166 eval
167825µs {
168822µs81.18ms $next_value_for{$self} = $code-> ();
# spent 1.17ms making 4 calls to Iterator::Util::__ANON__[Iterator/Util.pm:52], avg 293µs/call # spent 10µs making 4 calls to Iterator::Util::__ANON__[Iterator/Util.pm:158], avg 2µs/call
169 };
170
17181µs my $ex;
172845µs852µs if ($ex = Iterator::X::Am_Now_Exhausted->caught ())
# spent 52µs making 8 calls to Exception::Class::Base::caught, avg 7µs/call
173 {
174 # Starting off exhausted is okay
175 $is_exhausted{$self} = 1;
176 }
177 elsif ($@)
178 {
179 Iterator::X::User_Code_Error->throw (message => "$@",
180 eval_error => $@);
181 }
182
183823µs return;
184 }
185
186 # Method name: DESTROY
187 # Synopsis: (none)
188 # Description: Object destructor.
189 # Created: 07/27/2005 by EJR
190 # Parameters: None.
191 # Returns: Nothing.
192 # Exceptions: None.
193 # Notes: Invoked automatically by perl.
194 # Releases the hash entries used by the object.
195 # Module would leak memory otherwise.
196 sub DESTROY
197
# spent 71µs within Iterator::DESTROY which was called 8 times, avg 9µs/call: # 3 times (19µs+-19µs) by Iterator::DESTROY at line 199, avg 0s/call # 2 times (28µs+12µs) by Benchmark::Perl::Formance::find_interesting_result_paths at line 710 of lib/Benchmark/Perl/Formance.pm, avg 20µs/call # 2 times (12µs+0s) by Benchmark::Perl::Formance::find_interesting_result_paths at line 700 of lib/Benchmark/Perl/Formance.pm, avg 6µs/call # once (12µs+8µs) by Benchmark::Perl::Formance::find_interesting_result_paths at line 719 of lib/Benchmark/Perl/Formance.pm
{
19882µs my $self = shift;
199836µs30s delete $code_for{$self};
# spent 19µs making 3 calls to Iterator::DESTROY, avg 6µs/call, recursion: max depth 1, sum of overlapping time 19µs
20085µs delete $is_exhausted{$self};
201839µs delete $next_value_for{$self};
202 }
203
204 # Method name: value
205 # Synopsis: $next_value = $iterator->value();
206 # Description: Returns each value of the sequence in turn.
207 # Created: 07/27/2005 by EJR
208 # Parameters: None.
209 # Returns: Next value, as generated by caller's code ref.
210 # Exceptions: Iterator::X::Exhausted
211 # Notes: Keeps one forward-looking value for the iterator in
212 # %next_value_for. This is so we have something to
213 # return when user's code throws Am_Now_Exhausted.
214 sub value
215
# spent 4.64ms (407µs+4.24) within Iterator::value which was called 26 times, avg 179µs/call: # 13 times (188µs+883µs) by Iterator::Util::__ANON__[/home/ss5/perl5/perlbrew/perls/tapper-perl/lib/site_perl/5.16.3/Iterator/Util.pm:52] at line 50 of Iterator/Util.pm, avg 82µs/call # 10 times (150µs+2.01ms) by Benchmark::Perl::Formance::find_interesting_result_paths at line 706 of lib/Benchmark/Perl/Formance.pm, avg 216µs/call # 2 times (52µs+916µs) by Benchmark::Perl::Formance::find_interesting_result_paths at line 702 of lib/Benchmark/Perl/Formance.pm, avg 484µs/call # once (17µs+424µs) by Data::DPath::__ANON__[/home/ss5/perl5/perlbrew/perls/tapper-perl/lib/site_perl/5.16.3/Data/DPath.pm:47] at line 41 of Data/DPath.pm
{
216267µs my $self = shift;
217
2182616µs Iterator::X::Exhausted->throw(q{Iterator is exhausted})
219 if $is_exhausted{$self};
220
221 # The value that we'll be returning this time.
2222614µs my $this_value = $next_value_for{$self};
223
224 # Compute the value that we'll return next time
225 eval
2262660µs {
2272663µs265.58ms $next_value_for{$self} = $code_for{$self}->(@_);
# spent 3.26ms making 13 calls to Iterator::Util::__ANON__[Iterator/Util.pm:52], avg 251µs/call # spent 2.31ms making 13 calls to Iterator::Util::__ANON__[Iterator/Util.pm:158], avg 178µs/call
228 };
22926117µs34184µs if (my $ex = Iterator::X::Am_Now_Exhausted->caught ())
# spent 173µs making 26 calls to Exception::Class::Base::caught, avg 7µs/call # spent 11µs making 8 calls to Exception::Class::Base::__ANON__[Exception/Class/Base.pm:35], avg 1µs/call
230 {
231 # Aha, we're done; we'll have to stop next time.
232 $is_exhausted{$self} = 1;
233 }
234 elsif ($@)
235 {
236 Iterator::X::User_Code_Error->throw (message => "$@",
237 eval_error => $@);
238 }
239
2402684µs return $this_value;
241 }
242
243 # Method name: is_exhausted
244 # Synopsis: $boolean = $iterator->is_exhausted();
245 # Description: Flag indicating that the iterator is exhausted.
246 # Created: 07/27/2005 by EJR
247 # Parameters: None.
248 # Returns: Current value of %is_exhausted for this object.
249 # Exceptions: None.
250 sub is_exhausted
251
# spent 32µs within Iterator::is_exhausted which was called 17 times, avg 2µs/call: # 17 times (32µs+0s) by Iterator::Util::__ANON__[/home/ss5/perl5/perlbrew/perls/tapper-perl/lib/site_perl/5.16.3/Iterator/Util.pm:52] at line 48 of Iterator/Util.pm, avg 2µs/call
{
252175µs my $self = shift;
253
2541764µs return $is_exhausted{$self};
255 }
256
257 # Method name: isnt_exhausted
258 # Synopsis: $boolean = $iterator->isnt_exhausted();
259 # Description: Flag indicating that the iterator is NOT exhausted.
260 # Created: 07/27/2005 by EJR
261 # Parameters: None.
262 # Returns: Logical NOT of %is_exhausted for this object.
263 # Exceptions: None.
264 sub isnt_exhausted
265
# spent 37µs within Iterator::isnt_exhausted which was called 15 times, avg 2µs/call: # 10 times (23µs+0s) by Benchmark::Perl::Formance::find_interesting_result_paths at line 707 of lib/Benchmark/Perl/Formance.pm, avg 2µs/call # 2 times (5µs+0s) by Benchmark::Perl::Formance::find_interesting_result_paths at line 705 of lib/Benchmark/Perl/Formance.pm, avg 3µs/call # 2 times (5µs+0s) by Benchmark::Perl::Formance::find_interesting_result_paths at line 710 of lib/Benchmark/Perl/Formance.pm, avg 2µs/call # once (4µs+0s) by Benchmark::Perl::Formance::find_interesting_result_paths at line 700 of lib/Benchmark/Perl/Formance.pm
{
266154µs my $self = shift;
267
2681562µs return ! $is_exhausted{$self};
269 }
270
271} # end of encapsulation enclosure
272
273
274# Function name: is_done
275# Synopsis: Iterator::is_done ();
276# Description: Convenience function. Throws an Am_Now_Exhausted exception.
277# Created: 08/02/2005 by EJR, per Will Coleda's suggestion.
278# Parameters: None.
279# Returns: Doesn't return.
280# Exceptions: Iterator::X::Am_Now_Exhausted
281sub is_done
282
# spent 3.83ms (48µs+3.78) within Iterator::is_done which was called 8 times, avg 478µs/call: # 4 times (28µs+2.26ms) by Iterator::Util::__ANON__[/home/ss5/perl5/perlbrew/perls/tapper-perl/lib/site_perl/5.16.3/Iterator/Util.pm:158] at line 156 of Iterator/Util.pm, avg 571µs/call # 4 times (20µs+1.52ms) by Iterator::Util::__ANON__[/home/ss5/perl5/perlbrew/perls/tapper-perl/lib/site_perl/5.16.3/Iterator/Util.pm:52] at line 48 of Iterator/Util.pm, avg 386µs/call
{
283833µs83.78ms Iterator::X::Am_Now_Exhausted->throw()
# spent 3.78ms making 8 calls to Exception::Class::Base::throw, avg 472µs/call
284}
285
286
28713µs1;
288__END__