Filename | /home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/File/CountLines.pm |
Statements | Executed 38 statements in 1.02ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 2.59ms | 2.98ms | BEGIN@12 | File::CountLines::
1 | 1 | 1 | 1.92ms | 2.47ms | _cl_sysread_one_char | File::CountLines::
188 | 1 | 1 | 524µs | 524µs | CORE:sysread (opcode) | File::CountLines::
1 | 1 | 1 | 27µs | 33µs | BEGIN@2 | File::CountLines::
1 | 1 | 1 | 21µs | 2.49ms | count_lines | File::CountLines::
1 | 1 | 1 | 20µs | 101µs | BEGIN@8 | File::CountLines::
1 | 1 | 1 | 17µs | 17µs | CORE:open (opcode) | File::CountLines::
1 | 1 | 1 | 14µs | 61µs | BEGIN@11 | File::CountLines::
1 | 1 | 1 | 12µs | 23µs | BEGIN@3 | File::CountLines::
1 | 1 | 1 | 4µs | 4µs | CORE:close (opcode) | File::CountLines::
1 | 1 | 1 | 2µs | 2µs | CORE:binmode (opcode) | File::CountLines::
1 | 1 | 1 | 2µs | 2µs | CORE:subst (opcode) | File::CountLines::
0 | 0 | 0 | 0s | 0s | _cl_sysread_multiple_chars | File::CountLines::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package File::CountLines; | ||||
2 | 2 | 29µs | 2 | 40µ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 # spent 33µs making 1 call to File::CountLines::BEGIN@2
# spent 6µs making 1 call to strict::import |
3 | 2 | 47µs | 2 | 34µ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 # spent 23µs making 1 call to File::CountLines::BEGIN@3
# spent 11µs making 1 call to warnings::import |
4 | |||||
5 | 1 | 2µs | our $VERSION = '0.0.3'; | ||
6 | 1 | 2µs | our @EXPORT_OK = qw(count_lines); | ||
7 | |||||
8 | 3 | 92µs | 3 | 181µ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 # 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 |
9 | 1 | 5µs | 1 | 14µs | Exporter->import('import'); # spent 14µs making 1 call to Exporter::import |
10 | |||||
11 | 2 | 30µs | 2 | 108µ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 # spent 61µs making 1 call to File::CountLines::BEGIN@11
# spent 47µs making 1 call to Exporter::import |
12 | 2 | 158µs | 2 | 3.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 # spent 2.98ms making 1 call to File::CountLines::BEGIN@12
# spent 259µs making 1 call to charnames::import |
13 | |||||
14 | 1 | 3µs | our %StyleMap = ( | ||
15 | 1 | 11µs | 1 | 39µs | 'cr' => "\N{CARRIAGE RETURN}", # spent 39µs making 1 call to charnames::charnames |
16 | 1 | 9µs | 1 | 27µs | 'lf' => "\N{LINE FEED}", # spent 27µs making 1 call to charnames::charnames |
17 | 1 | 470µs | 2 | 60µ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 | |||||
21 | 1 | 1µs | our $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 | ||||
24 | 1 | 1µs | my $filename = shift; | ||
25 | 1 | 1µs | croak 'expected filename in call to count_lines()' | ||
26 | unless defined $filename; | ||||
27 | 1 | 1µs | my %options = @_; | ||
28 | 1 | 1µs | my $sep = $options{separator}; | ||
29 | 1 | 2µs | unless (defined $sep) { | ||
30 | 1 | 1µs | my $style = exists $options{style} ? $options{style} : 'native'; | ||
31 | 1 | 1µs | $sep = $StyleMap{$style}; | ||
32 | 1 | 1µs | die "Don't know how to map style '$style'" unless defined $sep; | ||
33 | } | ||||
34 | 1 | 2µs | if (length($sep) > 1) { | ||
35 | return _cl_sysread_multiple_chars( | ||||
36 | $filename, | ||||
37 | $sep, | ||||
38 | $options{blocksize} || $BlockSize, | ||||
39 | ); | ||||
40 | } else { | ||||
41 | 1 | 8µs | 1 | 2.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 | ||||
50 | 1 | 1µs | my ($filename, $sep, $blocksize) = @_; | ||
51 | 1 | 1µs | local $Carp::CarpLevel = 1; | ||
52 | 1 | 24µs | 1 | 17µ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: $!"; | ||||
54 | 1 | 8µs | 1 | 2µs | binmode $handle; # spent 2µs making 1 call to File::CountLines::CORE:binmode |
55 | 1 | 1µs | my $lines = 0; | ||
56 | 1 | 7µs | 1 | 2µ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 | 1 | 700ns | my $sysread_status; | ||
59 | 1 | 63µs | 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 | 1 | 1µs | die "Can't sysread() from file `$filename': $!" | ||
65 | unless defined ($sysread_status); | ||||
66 | 1 | 11µs | 1 | 4µs | close $handle or croak "Can't close file `$filename': $!"; # spent 4µs making 1 call to File::CountLines::CORE:close |
67 | 1 | 20µs | return $lines; | ||
68 | } | ||||
69 | |||||
70 | sub _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 | |||||
94 | 1 | 6µs | 1; | ||
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 | |||||
# 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 | |||||
# 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 | |||||
# 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 | |||||
# 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 |