| File | /usr/local/lib/perl5/5.8.8/SelectSaver.pm |
| Statements Executed | 3236 |
| Statement Execution Time | 55.5ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 461 | 1 | 1 | 30.9ms | 52.5ms | SelectSaver::new |
| 1383 | 3 | 2 | 14.6ms | 14.6ms | SelectSaver::CORE:select (opcode) |
| 0 | 0 | 0 | 0s | 0s | SelectSaver::BEGIN |
| 0 | 0 | 0 | 0s | 0s | SelectSaver::DESTROY |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package SelectSaver; | ||||
| 2 | |||||
| 3 | 1 | 5µs | our $VERSION = '1.01'; | ||
| 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 = new SelectSaver(FILEHANDLE); | ||||
| 15 | # FILEHANDLE is selected | ||||
| 16 | } | ||||
| 17 | # previous handle is selected | ||||
| 18 | |||||
| 19 | { | ||||
| 20 | my $saver = new SelectSaver; | ||||
| 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 | 3 | 123µs | 1 | 234µs | use Carp; # spent 234µs making 1 call to Exporter::import |
| 39 | 3 | 310µs | 1 | 242µs | use Symbol; # spent 242µs making 1 call to Exporter::import |
| 40 | |||||
| 41 | # spent 52.5ms (30.9+21.6) within SelectSaver::new which was called 461 times, avg 114µs/call:
# 461 times (30.9ms+21.6ms) by IO::Handle::autoflush at line 467 of IO/Handle.pm, avg 114µs/call | ||||
| 42 | 2305 | 42.8ms | @_ >= 1 && @_ <= 2 or croak 'usage: new SelectSaver [FILEHANDLE]'; | ||
| 43 | my $fh = select; # spent 4.10ms making 461 calls to SelectSaver::CORE:select, avg 9µs/call | ||||
| 44 | my $self = bless \$fh, $_[0]; | ||||
| 45 | select qualify($_[1], caller) if @_ > 1; # spent 9.57ms making 461 calls to Symbol::qualify, avg 21µs/call
# spent 7.94ms making 461 calls to SelectSaver::CORE:select, avg 17µs/call | ||||
| 46 | $self; | ||||
| 47 | } | ||||
| 48 | |||||
| 49 | sub DESTROY { | ||||
| 50 | 922 | 12.2ms | my $self = $_[0]; | ||
| 51 | select $$self; # spent 2.53ms making 461 calls to SelectSaver::CORE:select, avg 5µs/call | ||||
| 52 | } | ||||
| 53 | |||||
| 54 | 1 | 12µs | 1; | ||
# spent 14.6ms within SelectSaver::CORE:select which was called 1383 times, avg 11µs/call:
# 461 times (7.94ms+0s) by SelectSaver::new at line 45 of SelectSaver.pm, avg 17µs/call
# 461 times (4.10ms+0s) by SelectSaver::new at line 43 of SelectSaver.pm, avg 9µs/call
# 461 times (2.53ms+0s) by IO::Handle::autoflush at line 51 of SelectSaver.pm, avg 5µs/call |