| 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 | File::CountLines::BEGIN@12 |
| 1 | 1 | 1 | 1.92ms | 2.47ms | File::CountLines::_cl_sysread_one_char |
| 188 | 1 | 1 | 524µs | 524µs | File::CountLines::CORE:sysread (opcode) |
| 1 | 1 | 1 | 27µs | 33µs | File::CountLines::BEGIN@2 |
| 1 | 1 | 1 | 21µs | 2.49ms | File::CountLines::count_lines |
| 1 | 1 | 1 | 20µs | 101µs | File::CountLines::BEGIN@8 |
| 1 | 1 | 1 | 17µs | 17µs | File::CountLines::CORE:open (opcode) |
| 1 | 1 | 1 | 14µs | 61µs | File::CountLines::BEGIN@11 |
| 1 | 1 | 1 | 12µs | 23µs | File::CountLines::BEGIN@3 |
| 1 | 1 | 1 | 4µs | 4µs | File::CountLines::CORE:close (opcode) |
| 1 | 1 | 1 | 2µs | 2µs | File::CountLines::CORE:binmode (opcode) |
| 1 | 1 | 1 | 2µs | 2µs | File::CountLines::CORE:subst (opcode) |
| 0 | 0 | 0 | 0s | 0s | File::CountLines::_cl_sysread_multiple_chars |
| 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 | 6 | 8µ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}; | ||||
| 29 | 3 | 4µ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 | } | ||||
| 34 | 1 | 8µs | if (length($sep) > 1) { | ||
| 35 | return _cl_sysread_multiple_chars( | ||||
| 36 | $filename, | ||||
| 37 | $sep, | ||||
| 38 | $options{blocksize} || $BlockSize, | ||||
| 39 | ); | ||||
| 40 | } else { | ||||
| 41 | 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 | 11 | 138µs | my ($filename, $sep, $blocksize) = @_; | ||
| 51 | local $Carp::CarpLevel = 1; | ||||
| 52 | 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 | 2µs | binmode $handle; # spent 2µs making 1 call to File::CountLines::CORE:binmode | ||
| 55 | my $lines = 0; | ||||
| 56 | 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 | 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); | ||||
| 66 | 1 | 4µ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 | |||||
| 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 |