Filename | /usr/share/perl/5.10/Time/Local.pm |
Statements | Executed 81 statements in 1.37ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
3 | 2 | 1 | 34µs | 43µs | _daygm | Time::Local::
2 | 1 | 1 | 33µs | 60µs | timegm | Time::Local::
1 | 1 | 1 | 30µs | 94µs | BEGIN@5 | Time::Local::
1 | 1 | 1 | 24µs | 126µs | BEGIN@28 | Time::Local::
1 | 1 | 1 | 22µs | 99µs | BEGIN@4 | Time::Local::
1 | 1 | 1 | 14µs | 17µs | BEGIN@7 | Time::Local::
1 | 1 | 1 | 12µs | 16µs | BEGIN@6 | Time::Local::
1 | 1 | 1 | 11µs | 51µs | BEGIN@29 | Time::Local::
1 | 1 | 1 | 10µs | 44µs | BEGIN@30 | Time::Local::
1 | 1 | 1 | 9µs | 75µs | BEGIN@9 | Time::Local::
3 | 1 | 1 | 9µs | 9µs | CORE:pack (opcode) | Time::Local::
0 | 0 | 0 | 0s | 0s | _is_leap_year | Time::Local::
0 | 0 | 0 | 0s | 0s | _timegm | Time::Local::
0 | 0 | 0 | 0s | 0s | timegm_nocheck | Time::Local::
0 | 0 | 0 | 0s | 0s | timelocal | Time::Local::
0 | 0 | 0 | 0s | 0s | timelocal_nocheck | Time::Local::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Time::Local; | ||||
2 | |||||
3 | 1 | 1µs | require Exporter; | ||
4 | 3 | 52µs | 2 | 175µs | # spent 99µs (22+77) within Time::Local::BEGIN@4 which was called:
# once (22µs+77µs) by LWP::UserAgent::BEGIN@12 at line 4 # spent 99µs making 1 call to Time::Local::BEGIN@4
# spent 77µs making 1 call to Exporter::import |
5 | 3 | 48µs | 2 | 157µs | # spent 94µs (30+63) within Time::Local::BEGIN@5 which was called:
# once (30µs+63µs) by LWP::UserAgent::BEGIN@12 at line 5 # spent 94µs making 1 call to Time::Local::BEGIN@5
# spent 63µs making 1 call to Config::import |
6 | 3 | 26µs | 2 | 21µs | # spent 16µs (12+4) within Time::Local::BEGIN@6 which was called:
# once (12µs+4µs) by LWP::UserAgent::BEGIN@12 at line 6 # spent 16µs making 1 call to Time::Local::BEGIN@6
# spent 4µs making 1 call to strict::import |
7 | 3 | 40µs | 2 | 20µs | # spent 17µs (14+3) within Time::Local::BEGIN@7 which was called:
# once (14µs+3µs) by LWP::UserAgent::BEGIN@12 at line 7 # spent 17µs making 1 call to Time::Local::BEGIN@7
# spent 3µs making 1 call to integer::import |
8 | |||||
9 | 3 | 106µs | 2 | 141µs | # spent 75µs (9+66) within Time::Local::BEGIN@9 which was called:
# once (9µs+66µs) by LWP::UserAgent::BEGIN@12 at line 9 # spent 75µs making 1 call to Time::Local::BEGIN@9
# spent 66µs making 1 call to vars::import |
10 | 1 | 1µs | $VERSION = '1.1901'; | ||
11 | |||||
12 | 1 | 14µs | @ISA = qw( Exporter ); | ||
13 | 1 | 1µs | @EXPORT = qw( timegm timelocal ); | ||
14 | 1 | 1µs | @EXPORT_OK = qw( timegm_nocheck timelocal_nocheck ); | ||
15 | |||||
16 | 1 | 2µs | my @MonthDays = ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ); | ||
17 | |||||
18 | # Determine breakpoint for rolling century | ||||
19 | 1 | 29µs | my $ThisYear = ( localtime() )[5]; | ||
20 | 1 | 1µs | my $Breakpoint = ( $ThisYear + 50 ) % 100; | ||
21 | 1 | 600ns | my $NextCentury = $ThisYear - $ThisYear % 100; | ||
22 | 1 | 500ns | $NextCentury += 100 if $Breakpoint < 50; | ||
23 | 1 | 300ns | my $Century = $NextCentury - 100; | ||
24 | 1 | 300ns | my $SecOff = 0; | ||
25 | |||||
26 | 1 | 600ns | my ( %Options, %Cheat ); | ||
27 | |||||
28 | 3 | 60µs | 2 | 227µs | # spent 126µs (24+101) within Time::Local::BEGIN@28 which was called:
# once (24µs+101µs) by LWP::UserAgent::BEGIN@12 at line 28 # spent 126µs making 1 call to Time::Local::BEGIN@28
# spent 101µs making 1 call to constant::import |
29 | 3 | 44µs | 2 | 92µs | # spent 51µs (11+40) within Time::Local::BEGIN@29 which was called:
# once (11µs+40µs) by LWP::UserAgent::BEGIN@12 at line 29 # spent 51µs making 1 call to Time::Local::BEGIN@29
# spent 40µs making 1 call to constant::import |
30 | 3 | 820µs | 2 | 77µs | # spent 44µs (10+34) within Time::Local::BEGIN@30 which was called:
# once (10µs+34µs) by LWP::UserAgent::BEGIN@12 at line 30 # spent 44µs making 1 call to Time::Local::BEGIN@30
# spent 34µs making 1 call to constant::import |
31 | |||||
32 | 1 | 200ns | my $MaxInt; | ||
33 | 2 | 13µs | if ( $^O eq 'MacOS' ) { | ||
34 | # time_t is unsigned... | ||||
35 | $MaxInt = ( 1 << ( 8 * $Config{ivsize} ) ) - 1; | ||||
36 | } | ||||
37 | else { | ||||
38 | 1 | 4µs | 1 | 64µs | $MaxInt = ( ( 1 << ( 8 * $Config{ivsize} - 2 ) ) - 1 ) * 2 + 1; # spent 64µs making 1 call to Config::FETCH |
39 | } | ||||
40 | |||||
41 | 1 | 1µs | my $MaxDay = int( ( $MaxInt - ( SECS_PER_DAY / 2 ) ) / SECS_PER_DAY ) - 1; | ||
42 | |||||
43 | # Determine the EPOC day for this machine | ||||
44 | 1 | 300ns | my $Epoc = 0; | ||
45 | 2 | 7µs | if ( $^O eq 'vos' ) { | ||
46 | # work around posix-977 -- VOS doesn't handle dates in the range | ||||
47 | # 1970-1980. | ||||
48 | $Epoc = _daygm( 0, 0, 0, 1, 0, 70, 4, 0 ); | ||||
49 | } | ||||
50 | elsif ( $^O eq 'MacOS' ) { | ||||
51 | $MaxDay *=2 if $^O eq 'MacOS'; # time_t unsigned ... quick hack? | ||||
52 | # MacOS time() is seconds since 1 Jan 1904, localtime | ||||
53 | # so we need to calculate an offset to apply later | ||||
54 | $Epoc = 693901; | ||||
55 | $SecOff = timelocal( localtime(0)) - timelocal( gmtime(0) ) ; | ||||
56 | $Epoc += _daygm( gmtime(0) ); | ||||
57 | } | ||||
58 | else { | ||||
59 | 1 | 17µs | $Epoc = _daygm( gmtime(0) ); # spent 17µs making 1 call to Time::Local::_daygm | ||
60 | } | ||||
61 | |||||
62 | 1 | 1µs | %Cheat = (); # clear the cache as epoc has changed | ||
63 | |||||
64 | sub _daygm { | ||||
65 | |||||
66 | # This is written in such a byzantine way in order to avoid | ||||
67 | # lexical variables and sub calls, for speed | ||||
68 | return $_[3] + ( | ||||
69 | 9 | 47µs | 3 | 9µs | $Cheat{ pack( 'ss', @_[ 4, 5 ] ) } ||= do { # spent 9µs making 3 calls to Time::Local::CORE:pack, avg 3µs/call |
70 | my $month = ( $_[4] + 10 ) % 12; | ||||
71 | my $year = ( $_[5] + 1900 ) - ( $month / 10 ); | ||||
72 | |||||
73 | ( ( 365 * $year ) | ||||
74 | + ( $year / 4 ) | ||||
75 | - ( $year / 100 ) | ||||
76 | + ( $year / 400 ) | ||||
77 | + ( ( ( $month * 306 ) + 5 ) / 10 ) | ||||
78 | ) | ||||
79 | - $Epoc; | ||||
80 | } | ||||
81 | ); | ||||
82 | } | ||||
83 | |||||
84 | sub _timegm { | ||||
85 | my $sec = | ||||
86 | $SecOff + $_[0] + ( SECS_PER_MINUTE * $_[1] ) + ( SECS_PER_HOUR * $_[2] ); | ||||
87 | |||||
88 | return $sec + ( SECS_PER_DAY * &_daygm ); | ||||
89 | } | ||||
90 | |||||
91 | # spent 60µs (33+26) within Time::Local::timegm which was called 2 times, avg 30µs/call:
# 2 times (33µs+26µs) by Set::Infinite::BEGIN@18 at line 32 of Set/Infinite/Arithmetic.pm, avg 30µs/call | ||||
92 | 12 | 22µs | my ( $sec, $min, $hour, $mday, $month, $year ) = @_; | ||
93 | |||||
94 | if ( $year >= 1000 ) { | ||||
95 | $year -= 1900; | ||||
96 | } | ||||
97 | elsif ( $year < 100 and $year >= 0 ) { | ||||
98 | $year += ( $year > $Breakpoint ) ? $Century : $NextCentury; | ||||
99 | } | ||||
100 | |||||
101 | 14 | 8µs | unless ( $Options{no_range_check} ) { | ||
102 | croak "Month '$month' out of range 0..11" | ||||
103 | if $month > 11 | ||||
104 | or $month < 0; | ||||
105 | |||||
106 | my $md = $MonthDays[$month]; | ||||
107 | ++$md | ||||
108 | if $month == 1 && _is_leap_year( $year + 1900 ); | ||||
109 | |||||
110 | croak "Day '$mday' out of range 1..$md" if $mday > $md or $mday < 1; | ||||
111 | croak "Hour '$hour' out of range 0..23" if $hour > 23 or $hour < 0; | ||||
112 | croak "Minute '$min' out of range 0..59" if $min > 59 or $min < 0; | ||||
113 | croak "Second '$sec' out of range 0..59" if $sec > 59 or $sec < 0; | ||||
114 | } | ||||
115 | |||||
116 | 2 | 26µs | my $days = _daygm( undef, undef, undef, $mday, $month, $year ); # spent 26µs making 2 calls to Time::Local::_daygm, avg 13µs/call | ||
117 | |||||
118 | unless ($Options{no_range_check} or abs($days) < $MaxDay) { | ||||
119 | my $msg = ''; | ||||
120 | $msg .= "Day too big - $days > $MaxDay\n" if $days > $MaxDay; | ||||
121 | |||||
122 | $year += 1900; | ||||
123 | $msg .= "Cannot handle date ($sec, $min, $hour, $mday, $month, $year)"; | ||||
124 | |||||
125 | croak $msg; | ||||
126 | } | ||||
127 | |||||
128 | return $sec | ||||
129 | + $SecOff | ||||
130 | + ( SECS_PER_MINUTE * $min ) | ||||
131 | + ( SECS_PER_HOUR * $hour ) | ||||
132 | + ( SECS_PER_DAY * $days ); | ||||
133 | } | ||||
134 | |||||
135 | sub _is_leap_year { | ||||
136 | return 0 if $_[0] % 4; | ||||
137 | return 1 if $_[0] % 100; | ||||
138 | return 0 if $_[0] % 400; | ||||
139 | |||||
140 | return 1; | ||||
141 | } | ||||
142 | |||||
143 | sub timegm_nocheck { | ||||
144 | local $Options{no_range_check} = 1; | ||||
145 | return &timegm; | ||||
146 | } | ||||
147 | |||||
148 | sub timelocal { | ||||
149 | my $ref_t = &timegm; | ||||
150 | my $loc_for_ref_t = _timegm( localtime($ref_t) ); | ||||
151 | |||||
152 | my $zone_off = $loc_for_ref_t - $ref_t | ||||
153 | or return $loc_for_ref_t; | ||||
154 | |||||
155 | # Adjust for timezone | ||||
156 | my $loc_t = $ref_t - $zone_off; | ||||
157 | |||||
158 | # Are we close to a DST change or are we done | ||||
159 | my $dst_off = $ref_t - _timegm( localtime($loc_t) ); | ||||
160 | |||||
161 | # If this evaluates to true, it means that the value in $loc_t is | ||||
162 | # the _second_ hour after a DST change where the local time moves | ||||
163 | # backward. | ||||
164 | if ( ! $dst_off && | ||||
165 | ( ( $ref_t - SECS_PER_HOUR ) - _timegm( localtime( $loc_t - SECS_PER_HOUR ) ) < 0 ) | ||||
166 | ) { | ||||
167 | return $loc_t - SECS_PER_HOUR; | ||||
168 | } | ||||
169 | |||||
170 | # Adjust for DST change | ||||
171 | $loc_t += $dst_off; | ||||
172 | |||||
173 | return $loc_t if $dst_off > 0; | ||||
174 | |||||
175 | # If the original date was a non-extent gap in a forward DST jump, | ||||
176 | # we should now have the wrong answer - undo the DST adjustment | ||||
177 | my ( $s, $m, $h ) = localtime($loc_t); | ||||
178 | $loc_t -= $dst_off if $s != $_[0] || $m != $_[1] || $h != $_[2]; | ||||
179 | |||||
180 | return $loc_t; | ||||
181 | } | ||||
182 | |||||
183 | sub timelocal_nocheck { | ||||
184 | local $Options{no_range_check} = 1; | ||||
185 | return &timelocal; | ||||
186 | } | ||||
187 | |||||
188 | 1 | 21µs | 1; | ||
189 | |||||
190 | __END__ | ||||
# spent 9µs within Time::Local::CORE:pack which was called 3 times, avg 3µs/call:
# 3 times (9µs+0s) by Time::Local::_daygm at line 69, avg 3µs/call |