← Index
NYTProf Performance Profile   « block view • line view • sub view »
For /usr/local/src/github.com/foswiki/core/bin/view
  Run on Sun Dec 4 17:17:59 2011
Reported on Sun Dec 4 17:26:35 2011

Filename/usr/local/src/github.com/foswiki/core/lib/Foswiki/Iterator/FilterIterator.pm
StatementsExecuted 10898 statements in 70.6ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
947480.7ms1.94sFoswiki::Iterator::FilterIterator::::hasNextFoswiki::Iterator::FilterIterator::hasNext
4533647µs880µsFoswiki::Iterator::FilterIterator::::nextFoswiki::Iterator::FilterIterator::next
332136µs156µsFoswiki::Iterator::FilterIterator::::newFoswiki::Iterator::FilterIterator::new
11150µs57µsFoswiki::Iterator::FilterIterator::::BEGIN@13Foswiki::Iterator::FilterIterator::BEGIN@13
11127µs40µsFoswiki::Iterator::FilterIterator::::resetFoswiki::Iterator::FilterIterator::reset
11117µs35µsFoswiki::Iterator::FilterIterator::::BEGIN@14Foswiki::Iterator::FilterIterator::BEGIN@14
11116µs55µsFoswiki::Iterator::FilterIterator::::BEGIN@15Foswiki::Iterator::FilterIterator::BEGIN@15
1119µs9µsFoswiki::Iterator::FilterIterator::::BEGIN@17Foswiki::Iterator::FilterIterator::BEGIN@17
0000s0sFoswiki::Iterator::FilterIterator::::nextWebFoswiki::Iterator::FilterIterator::nextWeb
0000s0sFoswiki::Iterator::FilterIterator::::numberOfTopicsFoswiki::Iterator::FilterIterator::numberOfTopics
0000s0sFoswiki::Iterator::FilterIterator::::skipFoswiki::Iterator::FilterIterator::skip
0000s0sFoswiki::Iterator::FilterIterator::::sortResultsFoswiki::Iterator::FilterIterator::sortResults
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1# See bottom of file for license and copyright information
2
3=begin
4
5---+ package Foswiki::Iterator::FilterIterator
6
7Iterator that filters another iterator based on the results from a function.
8
9=cut
10
11package Foswiki::Iterator::FilterIterator;
12
13255µs264µs
# spent 57µs (50+7) within Foswiki::Iterator::FilterIterator::BEGIN@13 which was called: # once (50µs+7µs) by Foswiki::Search::InfoCache::BEGIN@26 at line 13
use strict;
# spent 57µs making 1 call to Foswiki::Iterator::FilterIterator::BEGIN@13 # spent 7µs making 1 call to strict::import
14244µs252µs
# spent 35µs (17+18) within Foswiki::Iterator::FilterIterator::BEGIN@14 which was called: # once (17µs+18µs) by Foswiki::Search::InfoCache::BEGIN@26 at line 14
use warnings;
# spent 35µs making 1 call to Foswiki::Iterator::FilterIterator::BEGIN@14 # spent 18µs making 1 call to warnings::import
15244µs293µs
# spent 55µs (16+38) within Foswiki::Iterator::FilterIterator::BEGIN@15 which was called: # once (16µs+38µs) by Foswiki::Search::InfoCache::BEGIN@26 at line 15
use Assert;
# spent 55µs making 1 call to Foswiki::Iterator::FilterIterator::BEGIN@15 # spent 38µs making 1 call to Assert::import
16
172923µs19µs
# spent 9µs within Foswiki::Iterator::FilterIterator::BEGIN@17 which was called: # once (9µs+0s) by Foswiki::Search::InfoCache::BEGIN@26 at line 17
use Foswiki::Iterator ();
# spent 9µs making 1 call to Foswiki::Iterator::FilterIterator::BEGIN@17
18115µsour @ISA = ('Foswiki::Iterator');
19
20=begin TML
21
22---++ ClassMethod new( $iter, $sub, $data )
23Construct a new iterator that will filter $iter based on the results from
24$sub. $sub should return 0 if the next() from $iter should be filtered and
251 if it should be treated as the next item in the sequence.
26
27$data is an optional arbitrary data item which will be passed to $sub in $_[1]
28
29=cut
30
31
# spent 156µs (136+21) within Foswiki::Iterator::FilterIterator::new which was called 3 times, avg 52µs/call: # once (55µs+7µs) by Foswiki::Store::Interfaces::QueryAlgorithm::getWebIterator at line 230 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Store/Interfaces/QueryAlgorithm.pm # once (45µs+7µs) by Foswiki::Search::InfoCache::getTopicListIterator at line 459 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Search/InfoCache.pm # once (36µs+7µs) by Foswiki::Store::Interfaces::QueryAlgorithm::addACLFilter at line 188 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Store/Interfaces/QueryAlgorithm.pm
sub new {
3230121µs my ( $class, $iter, $sub, $data ) = @_;
33311µs ASSERT( UNIVERSAL::isa( $iter, 'Foswiki::Iterator' ) ) if DEBUG;
# spent 11µs making 3 calls to Assert::ASSERTS_OFF, avg 4µs/call
34310µs ASSERT( ref($sub) eq 'CODE' ) if DEBUG;
# spent 10µs making 3 calls to Assert::ASSERTS_OFF, avg 3µs/call
35 my $this = bless( {}, $class );
36 $this->{iterator} = $iter;
37 $this->{filter} = $sub;
38 $this->{data} = $data;
39 $this->{next} = undef;
40 $this->{pending} = 0;
41 return $this;
42}
43
44#lie - give the unfiltered count for speed.
45sub numberOfTopics {
46 my $this = shift;
47 return $this->{iterator}->numberOfTopics();
48}
49
50sub nextWeb {
51 my $this = shift;
52 $this->{iterator}->nextWeb();
53}
54
55sub sortResults {
56 my $this = shift;
57 $this->{iterator}->sortResults(@_);
58}
59
60# See Foswiki::Iterator for a description of the general iterator contract
61
# spent 1.94s (80.7ms+1.86) within Foswiki::Iterator::FilterIterator::hasNext which was called 94 times, avg 20.7ms/call: # 45 times (234µs+0s) by Foswiki::Iterator::FilterIterator::next at line 118, avg 5µs/call # 22 times (779µs+1.64s) by Foswiki::Search::formatResults at line 1018 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Search.pm, avg 74.7ms/call # 22 times (79.4ms+213ms) by Foswiki::Store::QueryAlgorithms::BruteForce::_webQuery at line 181 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm, avg 13.3ms/call # 2 times (65µs+641µs) by Foswiki::Iterator::ProcessIterator::hasNext at line 45 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Iterator/ProcessIterator.pm, avg 353µs/call # once (43µs+3.59ms) by Foswiki::Search::searchWeb at line 371 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Search.pm # once (92µs+225µs) by Foswiki::Store::QueryAlgorithms::BruteForce::_webQuery at line 175 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm # once (7µs+0s) by Foswiki::Search::formatResults at line 711 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Search.pm
sub hasNext {
621067368.8ms my $this = shift;
63 return 1 if $this->{pending};
64482.60ms while ( $this->{iterator}->hasNext() ) {
# spent 2.02ms making 23 calls to Foswiki::Search::ResultSet::hasNext, avg 88µs/call # spent 581µs making 25 calls to Foswiki::ListIterator::hasNext, avg 23µs/call
65344872.7ms $this->{next} = $this->{iterator}->next();
# spent 72.2ms making 3426 calls to Foswiki::ListIterator::next, avg 21µs/call # spent 471µs making 22 calls to Foswiki::Search::ResultSet::next, avg 21µs/call
6668511.79s if ( &{ $this->{filter} }( $this->{next}, $this->{data} ) ) {
67 $this->{pending} = 1;
68 return 1;
69 }
70 }
71 return 0;
72}
73
74#WARNING: foswiki has always skipped results before evaluating the filter - this is for speed, but a terrible thing to do
75sub skip {
76 my $this = shift;
77 my $count = shift;
78
79 #ask CAN skip() for faster path
80 if ( $this->{iterator}->can('skip') ) {
81 $count = $this->{iterator}->skip($count);
82
83#SMELL, TODO, AAAARGH - don't want to drain the itr, but this is assuming too much.
84 $this->{next} = $this->{iterator}->{next};
85 }
86 else {
87
88 #brute force
89 while (
90 ( $count > 0
91 ) #must come first - don't want to advance the inner itr if count ==0
92 and $this->{iterator}->hasNext()
93 )
94 {
95 $count--;
96 $this->{next} =
97 $this->{iterator}->next()
98 ; #drain next, so hasNext goes to next element
99 }
100 }
101
102 if ( $count >= 0 ) {
103
104 #finished.
105 $this->{next} = undef;
106 $this->{pending} = 0;
107 }
108 print STDERR
109"--------------------------------------------FilterIterator::skip() => $count\n"
110 if Foswiki::Iterator::MONITOR;
111
112 return $count;
113}
114
115# See Foswiki::Iterator for a description of the general iterator contract
116
# spent 880µs (647+234) within Foswiki::Iterator::FilterIterator::next which was called 45 times, avg 20µs/call: # 22 times (326µs+117µs) by Foswiki::Search::formatResults at line 712 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Search.pm, avg 20µs/call # 22 times (304µs+112µs) by Foswiki::Store::QueryAlgorithms::BruteForce::_webQuery at line 176 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm, avg 19µs/call # once (17µs+5µs) by Foswiki::Iterator::ProcessIterator::next at line 51 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Iterator/ProcessIterator.pm
sub next {
117180606µs my $this = shift;
11845234µs return unless $this->hasNext();
# spent 234µs making 45 calls to Foswiki::Iterator::FilterIterator::hasNext, avg 5µs/call
119 $this->{pending} = 0;
120 return $this->{next};
121}
122
123# See Foswiki::Iterator for a description of the general iterator contract
124
# spent 40µs (27+12) within Foswiki::Iterator::FilterIterator::reset which was called: # once (27µs+12µs) by Foswiki::Store::QueryAlgorithms::BruteForce::_webQuery at line 174 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm
sub reset {
125527µs my ($this) = @_;
126
127112µs return unless ( $this->{iterator}->reset() );
# spent 12µs making 1 call to Foswiki::ListIterator::reset
128 $this->{next} = undef;
129 $this->{pending} = 0;
130
131 return 1;
132}
133
13416µs1;
135__END__