| Filename | /home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/5.22.0/SelectSaver.pm |
| Statements | Executed 14021 statements in 53.9ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 2002 | 1 | 1 | 29.9ms | 40.3ms | SelectSaver::new |
| 6006 | 3 | 1 | 9.19ms | 9.19ms | SelectSaver::CORE:select (opcode) |
| 2002 | 1 | 1 | 7.66ms | 8.04ms | SelectSaver::DESTROY |
| 1 | 1 | 1 | 7µs | 26µs | SelectSaver::BEGIN@38 |
| 1 | 1 | 1 | 4µs | 19µs | SelectSaver::BEGIN@39 |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package SelectSaver; | ||||
| 2 | |||||
| 3 | 1 | 200ns | our $VERSION = '1.02'; | ||
| 4 | |||||
| 5 | =head1 NAME | ||||
| 6 | |||||
| 7 | SelectSaver - save and restore selected file handle | ||||
| 8 | |||||
| 9 | =head1 SYNOPSIS | ||||
| 10 | |||||
| 11 | use SelectSaver; | ||||
| 12 | |||||
| 13 | { | ||||
| 14 | my $saver = SelectSaver->new(FILEHANDLE); | ||||
| 15 | # FILEHANDLE is selected | ||||
| 16 | } | ||||
| 17 | # previous handle is selected | ||||
| 18 | |||||
| 19 | { | ||||
| 20 | my $saver = SelectSaver->new; | ||||
| 21 | # new handle may be selected, or not | ||||
| 22 | } | ||||
| 23 | # previous handle is selected | ||||
| 24 | |||||
| 25 | =head1 DESCRIPTION | ||||
| 26 | |||||
| 27 | A C<SelectSaver> object contains a reference to the file handle that | ||||
| 28 | was selected when it was created. If its C<new> method gets an extra | ||||
| 29 | parameter, then that parameter is selected; otherwise, the selected | ||||
| 30 | file handle remains unchanged. | ||||
| 31 | |||||
| 32 | When a C<SelectSaver> is destroyed, it re-selects the file handle | ||||
| 33 | that was selected when it was created. | ||||
| 34 | |||||
| 35 | =cut | ||||
| 36 | |||||
| 37 | 1 | 5µs | require 5.000; | ||
| 38 | 2 | 14µs | 2 | 45µs | # spent 26µs (7+19) within SelectSaver::BEGIN@38 which was called:
# once (7µs+19µs) by IO::Handle::BEGIN@268 at line 38 # spent 26µs making 1 call to SelectSaver::BEGIN@38
# spent 19µs making 1 call to Exporter::import |
| 39 | 2 | 61µs | 2 | 34µs | # spent 19µs (4+15) within SelectSaver::BEGIN@39 which was called:
# once (4µs+15µs) by IO::Handle::BEGIN@268 at line 39 # spent 19µs making 1 call to SelectSaver::BEGIN@39
# spent 15µs making 1 call to Exporter::import |
| 40 | |||||
| 41 | # spent 40.3ms (29.9+10.4) within SelectSaver::new which was called 2002 times, avg 20µs/call:
# 2002 times (29.9ms+10.4ms) by IO::Handle::autoflush at line 497 of IO/Handle.pm, avg 20µs/call | ||||
| 42 | 2002 | 2.18ms | @_ >= 1 && @_ <= 2 or croak 'usage: SelectSaver->new( [FILEHANDLE] )'; | ||
| 43 | 2002 | 6.74ms | 2002 | 2.50ms | my $fh = select; # spent 2.50ms making 2002 calls to SelectSaver::CORE:select, avg 1µs/call |
| 44 | 2002 | 1.55ms | my $self = bless \$fh, $_[0]; | ||
| 45 | 2002 | 18.7ms | 4004 | 7.91ms | select qualify($_[1], caller) if @_ > 1; # spent 6.32ms making 2002 calls to SelectSaver::CORE:select, avg 3µs/call
# spent 1.59ms making 2002 calls to Symbol::qualify, avg 794ns/call |
| 46 | 2002 | 9.60ms | $self; | ||
| 47 | } | ||||
| 48 | |||||
| 49 | # spent 8.04ms (7.66+373µs) within SelectSaver::DESTROY which was called 2002 times, avg 4µs/call:
# 2002 times (7.66ms+373µs) by IO::Handle::autoflush at line 45 of IO/Socket.pm, avg 4µs/call | ||||
| 50 | 2002 | 576µs | my $self = $_[0]; | ||
| 51 | 2002 | 14.4ms | 2002 | 373µs | select $$self; # spent 373µs making 2002 calls to SelectSaver::CORE:select, avg 186ns/call |
| 52 | } | ||||
| 53 | |||||
| 54 | 1 | 2µs | 1; | ||
# spent 9.19ms within SelectSaver::CORE:select which was called 6006 times, avg 2µs/call:
# 2002 times (6.32ms+0s) by SelectSaver::new at line 45, avg 3µs/call
# 2002 times (2.50ms+0s) by SelectSaver::new at line 43, avg 1µs/call
# 2002 times (373µs+0s) by SelectSaver::DESTROY at line 51, avg 186ns/call |