← Index
NYTProf Performance Profile   « block view • line view • sub view »
For bin/hailo
  Run on Thu Oct 21 22:50:37 2010
Reported on Thu Oct 21 22:52:10 2010

Filename/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/File/CountLines.pm
StatementsExecuted 38 statements in 1.02ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1112.59ms2.98msFile::CountLines::::BEGIN@12File::CountLines::BEGIN@12
1111.92ms2.47msFile::CountLines::::_cl_sysread_one_charFile::CountLines::_cl_sysread_one_char
18811524µs524µsFile::CountLines::::CORE:sysreadFile::CountLines::CORE:sysread (opcode)
11127µs33µsFile::CountLines::::BEGIN@2File::CountLines::BEGIN@2
11121µs2.49msFile::CountLines::::count_linesFile::CountLines::count_lines
11120µs101µsFile::CountLines::::BEGIN@8File::CountLines::BEGIN@8
11117µs17µsFile::CountLines::::CORE:openFile::CountLines::CORE:open (opcode)
11114µs61µsFile::CountLines::::BEGIN@11File::CountLines::BEGIN@11
11112µs23µsFile::CountLines::::BEGIN@3File::CountLines::BEGIN@3
1114µs4µsFile::CountLines::::CORE:closeFile::CountLines::CORE:close (opcode)
1112µs2µsFile::CountLines::::CORE:binmodeFile::CountLines::CORE:binmode (opcode)
1112µs2µsFile::CountLines::::CORE:substFile::CountLines::CORE:subst (opcode)
0000s0sFile::CountLines::::_cl_sysread_multiple_charsFile::CountLines::_cl_sysread_multiple_chars
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package File::CountLines;
2229µs240µs
# spent 33µs (27+6) within File::CountLines::BEGIN@2 which was called: # once (27µs+6µs) by Hailo::Command::__ANON__[lib/Hailo/Command.pm:307] at line 2
use strict;
# spent 33µs making 1 call to File::CountLines::BEGIN@2 # spent 6µs making 1 call to strict::import
3247µs234µs
# spent 23µs (12+11) within File::CountLines::BEGIN@3 which was called: # once (12µs+11µs) by Hailo::Command::__ANON__[lib/Hailo/Command.pm:307] at line 3
use warnings;
# spent 23µs making 1 call to File::CountLines::BEGIN@3 # spent 11µs making 1 call to warnings::import
4
512µsour $VERSION = '0.0.3';
612µsour @EXPORT_OK = qw(count_lines);
7
8392µs3181µs
# spent 101µs (20+80) within File::CountLines::BEGIN@8 which was called: # once (20µs+80µs) by Hailo::Command::__ANON__[lib/Hailo/Command.pm:307] at line 8
use Exporter 5.057;
# spent 101µs making 1 call to File::CountLines::BEGIN@8 # spent 46µs making 1 call to UNIVERSAL::VERSION # spent 35µs making 1 call to Exporter::import
915µs114µsExporter->import('import');
# spent 14µs making 1 call to Exporter::import
10
11230µs2108µs
# spent 61µs (14+47) within File::CountLines::BEGIN@11 which was called: # once (14µs+47µs) by Hailo::Command::__ANON__[lib/Hailo/Command.pm:307] at line 11
use Carp qw(croak);
# spent 61µs making 1 call to File::CountLines::BEGIN@11 # spent 47µs making 1 call to Exporter::import
122158µs23.24ms
# spent 2.98ms (2.59+389µs) within File::CountLines::BEGIN@12 which was called: # once (2.59ms+389µs) by Hailo::Command::__ANON__[lib/Hailo/Command.pm:307] at line 12
use charnames qw(:full);
# spent 2.98ms making 1 call to File::CountLines::BEGIN@12 # spent 259µs making 1 call to charnames::import
13
1413µsour %StyleMap = (
15111µs139µs 'cr' => "\N{CARRIAGE RETURN}",
# spent 39µs making 1 call to charnames::charnames
1619µs127µs 'lf' => "\N{LINE FEED}",
# spent 27µs making 1 call to charnames::charnames
171470µs260µs 'crlf' => "\N{CARRIAGE RETURN}\N{LINE FEED}",
# spent 60µs making 2 calls to charnames::charnames, avg 30µs/call
18 'native' => "\n",
19);
20
2111µsour $BlockSize = 4096;
22
23
# spent 2.49ms (21µs+2.47) within File::CountLines::count_lines which was called: # once (21µs+2.47ms) by Hailo::Command::train_progress at line 311 of lib/Hailo/Command.pm
sub count_lines {
2468µs my $filename = shift;
25 croak 'expected filename in call to count_lines()'
26 unless defined $filename;
27 my %options = @_;
28 my $sep = $options{separator};
2934µs unless (defined $sep) {
30 my $style = exists $options{style} ? $options{style} : 'native';
31 $sep = $StyleMap{$style};
32 die "Don't know how to map style '$style'" unless defined $sep;
33 }
3418µs if (length($sep) > 1) {
35 return _cl_sysread_multiple_chars(
36 $filename,
37 $sep,
38 $options{blocksize} || $BlockSize,
39 );
40 } else {
4112.47ms return _cl_sysread_one_char(
# spent 2.47ms making 1 call to File::CountLines::_cl_sysread_one_char
42 $filename,
43 $sep,
44 $options{blocksize} || $BlockSize,
45 );
46 }
47}
48
49
# spent 2.47ms (1.92+549µs) within File::CountLines::_cl_sysread_one_char which was called: # once (1.92ms+549µs) by File::CountLines::count_lines at line 41
sub _cl_sysread_one_char {
5011138µs my ($filename, $sep, $blocksize) = @_;
51 local $Carp::CarpLevel = 1;
52117µs open my $handle, '<:raw', $filename
# spent 17µs making 1 call to File::CountLines::CORE:open
53 or croak "Can't open file `$filename' for reading: $!";
5412µs binmode $handle;
# spent 2µs making 1 call to File::CountLines::CORE:binmode
55 my $lines = 0;
5612µs $sep =~ s/([\\{}])/\\$1/g;
# spent 2µs making 1 call to File::CountLines::CORE:subst
57 # need eval here because tr/// doesn't interpolate
58 my $sysread_status;
59 eval qq[
# spent 2.33ms executing statements in string eval
60 while (\$sysread_status = sysread \$handle, my \$buffer, $blocksize) {
61 \$lines += (\$buffer =~ tr{$sep}{});
62 }
63 ];
64 die "Can't sysread() from file `$filename': $!"
65 unless defined ($sysread_status);
6614µs close $handle or croak "Can't close file `$filename': $!";
# spent 4µs making 1 call to File::CountLines::CORE:close
67 return $lines;
68}
69
70sub _cl_sysread_multiple_chars {
71 my ($filename, $sep, $blocksize) = @_;
72 local $Carp::CarpLevel = 1;
73 open my $handle, '<:raw', $filename
74 or croak "Can't open file `$filename' for reading: $!";
75 binmode $handle;
76 my $len = length($sep);
77 my $lines = 0;
78 my $buffer = '';
79 my $sysread_status;
80 while ($sysread_status = sysread $handle, $buffer, $blocksize, length($buffer)) {
81 my $offset = -$len;
82 while (-1 != ($offset = index $buffer, $sep, $offset + $len)) {
83 $lines++;
84 }
85 # we assume $len >= 2; otherwise use _cl_sysread_one_char()
86 $buffer = substr $buffer, 1 - $len;
87 }
88 die "Can't sysread() from file `$filename': $!"
89 unless defined ($sysread_status);
90 close $handle or croak "Can't close file `$filename': $!";
91 return $lines;
92}
93
9416µs1;
95
96__END__
 
# spent 2µs within File::CountLines::CORE:binmode which was called: # once (2µs+0s) by File::CountLines::_cl_sysread_one_char at line 54
sub File::CountLines::CORE:binmode; # opcode
# spent 4µs within File::CountLines::CORE:close which was called: # once (4µs+0s) by File::CountLines::_cl_sysread_one_char at line 66
sub File::CountLines::CORE:close; # opcode
# spent 17µs within File::CountLines::CORE:open which was called: # once (17µs+0s) by File::CountLines::_cl_sysread_one_char at line 52
sub File::CountLines::CORE:open; # opcode
# spent 2µs within File::CountLines::CORE:subst which was called: # once (2µs+0s) by File::CountLines::_cl_sysread_one_char at line 56
sub File::CountLines::CORE:subst; # opcode
# spent 524µs within File::CountLines::CORE:sysread which was called 188 times, avg 3µs/call: # 188 times (524µs+0s) by File::CountLines::_cl_sysread_one_char at line 2 of (eval 91)[File/CountLines.pm:59], avg 3µs/call
sub File::CountLines::CORE:sysread; # opcode