← Index
NYTProf Performance Profile   « block view • line view • sub view »
For lexer.pl
  Run on Thu Mar 22 18:01:49 2012
Reported on Thu Mar 22 18:02:03 2012

Filename/Users/smash/playground/Parse-Lexer/lib/Parse/Lexer.pm
StatementsExecuted 1703 statements in 14.0ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1117.94ms13.4msParse::Lexer::::BEGIN@17Parse::Lexer::BEGIN@17
551214.23ms4.23msParse::Lexer::::CORE:regcompParse::Lexer::CORE:regcomp (opcode)
1113.91ms3.97msParse::Lexer::::BEGIN@5Parse::Lexer::BEGIN@5
80113.10ms7.78msParse::Lexer::::__lexParse::Lexer::__lex
1611881µs8.83msParse::Lexer::::nextParse::Lexer::next
111831µs924µsParse::Lexer::::BEGIN@4Parse::Lexer::BEGIN@4
32531288µs288µsParse::Lexer::::CORE:substParse::Lexer::CORE:subst (opcode)
30611271µs271µsParse::Lexer::::CORE:matchParse::Lexer::CORE:match (opcode)
111129µs129µsParse::Lexer::::BEGIN@3Parse::Lexer::BEGIN@3
812176µs76µsParse::Lexer::::CORE:getcParse::Lexer::CORE:getc (opcode)
11117µs17µsParse::Lexer::::newParse::Lexer::new
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Parse::Lexer;
2
33170µs1129µs
# spent 129µs within Parse::Lexer::BEGIN@3 which was called: # once (129µs+0s) by main::BEGIN@2 at line 3
use 5.006;
# spent 129µs making 1 call to Parse::Lexer::BEGIN@3
43786µs2931µs
# spent 924µs (831+93) within Parse::Lexer::BEGIN@4 which was called: # once (831µs+93µs) by main::BEGIN@2 at line 4
use strict;
# spent 924µs making 1 call to Parse::Lexer::BEGIN@4 # spent 7µs making 1 call to strict::import
533.71ms23.99ms
# spent 3.97ms (3.91+53µs) within Parse::Lexer::BEGIN@5 which was called: # once (3.91ms+53µs) by main::BEGIN@2 at line 5
use warnings;
# spent 3.97ms making 1 call to Parse::Lexer::BEGIN@5 # spent 22µs making 1 call to warnings::import
6
7=head1 NAME
8
9Parse::Lexer - The great new Parse::Lexer!
10
11=head1 VERSION
12
13Version 0.01
14
15=cut
16
173727µs213.4ms
# spent 13.4ms (7.94+5.46) within Parse::Lexer::BEGIN@17 which was called: # once (7.94ms+5.46ms) by main::BEGIN@2 at line 17
use Data::Dumper;
# spent 13.4ms making 1 call to Parse::Lexer::BEGIN@17 # spent 48µs making 1 call to Exporter::import
18
1911µsour $VERSION = '0.01';
20
21# XXX
221300nsour $c = '';
231300nsour $buf = '';
24125µs116µsour $la = getc(STDIN);
# spent 16µs making 1 call to Parse::Lexer::CORE:getc
25
26=head1 SYNOPSIS
27
28Quick summary of what the module does.
29
30Perhaps a little code snippet.
31
32 use Parse::Lexer;
33
34 my $tokenizer = Parse::Lexer->new(
35 PLUS => qr/\+/,
36 MINUS => qr/\-/,
37 NUMBER => qr/[0-9]+/,
38 IDENT => qr/[a-z]+/,
39 );
40 $tokenizer->parse;
41
42=head1 EXPORT
43
44A list of functions that can be exported. You can delete this section
45if you don't export anything, such as for a purely object-oriented module.
46
47=head1 SUBROUTINES/METHODS
48
49=head2 new
50
51=cut
52
53
# spent 17µs within Parse::Lexer::new which was called: # once (17µs+0s) by main::RUNTIME at line 4 of lexer.pl
sub new {
54319µs my ($class, %re) = @_;
55 my $self = bless({re=>{%re}}, $class);
56
57 return $self;
58}
59
60=head2 next
61
62=cut
63
64
# spent 8.83ms (881µs+7.95) within Parse::Lexer::next which was called 16 times, avg 552µs/call: # 16 times (881µs+7.95ms) by main::RUNTIME at line 11 of lexer.pl, avg 552µs/call
sub next {
654826µs my ($self, $stream, $sub) = @_;
66 $stream = 'STDIN' unless $stream;
67
68 while (defined $la) {
69480893µs $c = $la if defined($la);
70
71 $buf .= $c;
728059µs $la = getc($stream);
# spent 59µs making 80 calls to Parse::Lexer::CORE:getc, avg 740ns/call
73
7480114µs $buf =~ s/^[ \n\t]+//; # XXX
# spent 114µs making 80 calls to Parse::Lexer::CORE:subst, avg 1µs/call
75
76807.78ms my @r = $self->__lex();
# spent 7.78ms making 80 calls to Parse::Lexer::__lex, avg 97µs/call
77 #&$sub(@r) if (@r>1);
78 return(@r) if (@r>1);
79 }
80}
81
82
# spent 7.78ms (3.10+4.67) within Parse::Lexer::__lex which was called 80 times, avg 97µs/call: # 80 times (3.10ms+4.67ms) by Parse::Lexer::next at line 76, avg 97µs/call
sub __lex {
83225351µs my ($self) = @_;
84
85#print "BUF $buf C $c LA $la\n";
86 foreach my $token (keys %{$self->{re}}) {
87620425µs my $re = $self->{re}->{$token};
88
893106.89ms if (defined $la) {
90 #if ($buf =~ m/^$re$/ and "$buf$la" !~ m/^$re$/) {
9110944.63ms if ( ("$buf$la" !~ m/^$re$/) and ($buf =~ s/^($re)//) ) {
# spent 4.19ms making 547 calls to Parse::Lexer::CORE:regcomp, avg 8µs/call # spent 271µs making 306 calls to Parse::Lexer::CORE:match, avg 885ns/call # spent 170µs making 241 calls to Parse::Lexer::CORE:subst, avg 705ns/call
92 return ($token => $1);
93 }
94 }
95 else {
96845µs return ($token => $1) if $buf =~ s/^($re)$//;
# spent 40µs making 4 calls to Parse::Lexer::CORE:regcomp, avg 10µs/call # spent 4µs making 4 calls to Parse::Lexer::CORE:subst, avg 1µs/call
97 }
98 }
99
100 return undef;
101}
102
103=head1 AUTHOR
104
105Nuno Carvalho, C<< <smash at cpan.org> >>
106
107=head1 BUGS
108
109Please report any bugs or feature requests to C<bug-parse-lexer at rt.cpan.org>, or through
110the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Parse-Lexer>. I will be notified, and then you'll
111automatically be notified of progress on your bug as I make changes.
112
- -
116=head1 SUPPORT
117
118You can find documentation for this module with the perldoc command.
119
120 perldoc Parse::Lexer
121
122
123You can also look for information at:
124
125=over 4
126
127=item * RT: CPAN's request tracker (report bugs here)
128
129L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Parse-Lexer>
130
131=item * AnnoCPAN: Annotated CPAN documentation
132
133L<http://annocpan.org/dist/Parse-Lexer>
134
135=item * CPAN Ratings
136
137L<http://cpanratings.perl.org/d/Parse-Lexer>
138
139=item * Search CPAN
140
141L<http://search.cpan.org/dist/Parse-Lexer/>
142
143=back
144
145
146=head1 ACKNOWLEDGEMENTS
147
148
149=head1 LICENSE AND COPYRIGHT
150
151Copyright 2012 Nuno Carvalho.
152
153This program is free software; you can redistribute it and/or modify it
154under the terms of either: the GNU General Public License as published
155by the Free Software Foundation; or the Artistic License.
156
157See http://dev.perl.org/licenses/ for more information.
158
159
160=cut
161
16219µs1; # End of Parse::Lexer
 
# spent 76µs within Parse::Lexer::CORE:getc which was called 81 times, avg 933ns/call: # 80 times (59µs+0s) by Parse::Lexer::next at line 72, avg 740ns/call # once (16µs+0s) by main::BEGIN@2 at line 24
sub Parse::Lexer::CORE:getc; # opcode
# spent 271µs within Parse::Lexer::CORE:match which was called 306 times, avg 885ns/call: # 306 times (271µs+0s) by Parse::Lexer::__lex at line 91, avg 885ns/call
sub Parse::Lexer::CORE:match; # opcode
# spent 4.23ms within Parse::Lexer::CORE:regcomp which was called 551 times, avg 8µs/call: # 547 times (4.19ms+0s) by Parse::Lexer::__lex at line 91, avg 8µs/call # 4 times (40µs+0s) by Parse::Lexer::__lex at line 96, avg 10µs/call
sub Parse::Lexer::CORE:regcomp; # opcode
# spent 288µs within Parse::Lexer::CORE:subst which was called 325 times, avg 886ns/call: # 241 times (170µs+0s) by Parse::Lexer::__lex at line 91, avg 705ns/call # 80 times (114µs+0s) by Parse::Lexer::next at line 74, avg 1µs/call # 4 times (4µs+0s) by Parse::Lexer::__lex at line 96, avg 1µs/call
sub Parse::Lexer::CORE:subst; # opcode