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