Filename | /usr/local/lib/perl5/5.24/SelectSaver.pm |
Statements | Executed 22554 statements in 264ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
3221 | 1 | 1 | 171ms | 237ms | new | SelectSaver::
3221 | 1 | 1 | 51.7ms | 60.1ms | DESTROY | SelectSaver::
9663 | 3 | 1 | 37.1ms | 37.1ms | CORE:select (opcode) | SelectSaver::
1 | 1 | 1 | 34µs | 169µs | BEGIN@38 | SelectSaver::
1 | 1 | 1 | 19µs | 150µs | BEGIN@39 | SelectSaver::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package SelectSaver; | ||||
2 | |||||
3 | 1 | 2µs | 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 | 14µs | require 5.000; | ||
38 | 2 | 52µs | 2 | 305µs | # spent 169µs (34+135) within SelectSaver::BEGIN@38 which was called:
# once (34µs+135µs) by IO::Handle::BEGIN@268 at line 38 # spent 169µs making 1 call to SelectSaver::BEGIN@38
# spent 135µs making 1 call to Exporter::import |
39 | 2 | 217µs | 2 | 281µs | # spent 150µs (19+131) within SelectSaver::BEGIN@39 which was called:
# once (19µs+131µs) by IO::Handle::BEGIN@268 at line 39 # spent 150µs making 1 call to SelectSaver::BEGIN@39
# spent 131µs making 1 call to Exporter::import |
40 | |||||
41 | # spent 237ms (171+66.3) within SelectSaver::new which was called 3221 times, avg 74µs/call:
# 3221 times (171ms+66.3ms) by IO::Handle::autoflush at line 497 of IO/Handle.pm, avg 74µs/call | ||||
42 | 3221 | 13.5ms | @_ >= 1 && @_ <= 2 or croak 'usage: SelectSaver->new( [FILEHANDLE] )'; | ||
43 | 3221 | 59.3ms | 3221 | 19.8ms | my $fh = select; # spent 19.8ms making 3221 calls to SelectSaver::CORE:select, avg 6µs/call |
44 | 3221 | 12.6ms | my $self = bless \$fh, $_[0]; | ||
45 | 3221 | 82.8ms | 6442 | 46.5ms | select qualify($_[1], caller) if @_ > 1; # spent 37.6ms making 3221 calls to Symbol::qualify, avg 12µs/call
# spent 8.84ms making 3221 calls to SelectSaver::CORE:select, avg 3µs/call |
46 | 3221 | 31.3ms | $self; | ||
47 | } | ||||
48 | |||||
49 | # spent 60.1ms (51.7+8.44) within SelectSaver::DESTROY which was called 3221 times, avg 19µs/call:
# 3221 times (51.7ms+8.44ms) by IO::Handle::autoflush at line 500 of IO/Handle.pm, avg 19µs/call | ||||
50 | 3221 | 6.73ms | my $self = $_[0]; | ||
51 | 3221 | 58.0ms | 3221 | 8.44ms | select $$self; # spent 8.44ms making 3221 calls to SelectSaver::CORE:select, avg 3µs/call |
52 | } | ||||
53 | |||||
54 | 1 | 7µs | 1; | ||
# spent 37.1ms within SelectSaver::CORE:select which was called 9663 times, avg 4µs/call:
# 3221 times (19.8ms+0s) by SelectSaver::new at line 43, avg 6µs/call
# 3221 times (8.84ms+0s) by SelectSaver::new at line 45, avg 3µs/call
# 3221 times (8.44ms+0s) by SelectSaver::DESTROY at line 51, avg 3µs/call |