Filename | /usr/lib/perl5/5.14/Time/Local.pm |
Statements | Executed 679200 statements in 2.19s |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
19964 | 1 | 1 | 942ms | 2.16s | timelocal | Time::Local::
79857 | 3 | 1 | 435ms | 530ms | _daygm | Time::Local::
59892 | 3 | 1 | 390ms | 770ms | _timegm | Time::Local::
19964 | 1 | 1 | 296ms | 446ms | timegm | Time::Local::
79857 | 1 | 1 | 95.5ms | 95.5ms | CORE:pack (opcode) | Time::Local::
80 | 1 | 1 | 261µs | 261µs | _is_leap_year | Time::Local::
1 | 1 | 1 | 217µs | 291µs | BEGIN@4 | Time::Local::
1 | 1 | 1 | 19µs | 38µs | BEGIN@5 | Time::Local::
1 | 1 | 1 | 18µs | 95µs | BEGIN@27 | Time::Local::
1 | 1 | 1 | 13µs | 19µs | BEGIN@6 | Time::Local::
1 | 1 | 1 | 12µs | 64µs | BEGIN@28 | Time::Local::
1 | 1 | 1 | 12µs | 60µs | BEGIN@29 | Time::Local::
1 | 1 | 1 | 12µs | 117µs | BEGIN@8 | Time::Local::
0 | 0 | 0 | 0s | 0s | timegm_nocheck | 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 | 500ns | require Exporter; | ||
4 | 2 | 60µs | 2 | 366µs | # spent 291µs (217+75) within Time::Local::BEGIN@4 which was called:
# once (217µs+75µs) by Archive::Zip::Member::BEGIN@21 at line 4 # spent 291µs making 1 call to Time::Local::BEGIN@4
# spent 75µs making 1 call to Exporter::import |
5 | 2 | 56µs | 2 | 57µs | # spent 38µs (19+19) within Time::Local::BEGIN@5 which was called:
# once (19µs+19µs) by Archive::Zip::Member::BEGIN@21 at line 5 # spent 38µs making 1 call to Time::Local::BEGIN@5
# spent 19µs making 1 call to Config::import |
6 | 2 | 58µs | 2 | 24µs | # spent 19µs (13+5) within Time::Local::BEGIN@6 which was called:
# once (13µs+5µs) by Archive::Zip::Member::BEGIN@21 at line 6 # spent 19µs making 1 call to Time::Local::BEGIN@6
# spent 5µs making 1 call to strict::import |
7 | |||||
8 | 2 | 203µs | 2 | 222µs | # spent 117µs (12+105) within Time::Local::BEGIN@8 which was called:
# once (12µs+105µs) by Archive::Zip::Member::BEGIN@21 at line 8 # spent 117µs making 1 call to Time::Local::BEGIN@8
# spent 105µs making 1 call to vars::import |
9 | 1 | 1µs | $VERSION = '1.2000'; | ||
10 | |||||
11 | 1 | 9µs | @ISA = qw( Exporter ); | ||
12 | 1 | 2µs | @EXPORT = qw( timegm timelocal ); | ||
13 | 1 | 2µs | @EXPORT_OK = qw( timegm_nocheck timelocal_nocheck ); | ||
14 | |||||
15 | 1 | 2µs | my @MonthDays = ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ); | ||
16 | |||||
17 | # Determine breakpoint for rolling century | ||||
18 | 1 | 30µs | my $ThisYear = ( localtime() )[5]; | ||
19 | 1 | 3µs | my $Breakpoint = ( $ThisYear + 50 ) % 100; | ||
20 | 1 | 2µs | my $NextCentury = $ThisYear - $ThisYear % 100; | ||
21 | 1 | 500ns | $NextCentury += 100 if $Breakpoint < 50; | ||
22 | 1 | 500ns | my $Century = $NextCentury - 100; | ||
23 | 1 | 500ns | my $SecOff = 0; | ||
24 | |||||
25 | 1 | 500ns | my ( %Options, %Cheat ); | ||
26 | |||||
27 | 2 | 61µs | 2 | 173µs | # spent 95µs (18+77) within Time::Local::BEGIN@27 which was called:
# once (18µs+77µs) by Archive::Zip::Member::BEGIN@21 at line 27 # spent 95µs making 1 call to Time::Local::BEGIN@27
# spent 77µs making 1 call to constant::import |
28 | 2 | 54µs | 2 | 115µs | # spent 64µs (12+51) within Time::Local::BEGIN@28 which was called:
# once (12µs+51µs) by Archive::Zip::Member::BEGIN@21 at line 28 # spent 64µs making 1 call to Time::Local::BEGIN@28
# spent 51µs making 1 call to constant::import |
29 | 2 | 1.54ms | 2 | 108µs | # spent 60µs (12+48) within Time::Local::BEGIN@29 which was called:
# once (12µs+48µs) by Archive::Zip::Member::BEGIN@21 at line 29 # spent 60µs making 1 call to Time::Local::BEGIN@29
# spent 48µs making 1 call to constant::import |
30 | |||||
31 | 1 | 500ns | my $MaxDay; | ||
32 | 1 | 2µ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 | 500ns | $MaxDay = 365 * (2**31); | ||
47 | } | ||||
48 | |||||
49 | # Determine the EPOC day for this machine | ||||
50 | 1 | 500ns | my $Epoc = 0; | ||
51 | 1 | 3µ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 | 11µs | 1 | 34µs | $Epoc = _daygm( gmtime(0) ); # spent 34µs making 1 call to Time::Local::_daygm |
66 | } | ||||
67 | |||||
68 | 1 | 2µs | %Cheat = (); # clear the cache as epoc has changed | ||
69 | |||||
70 | # spent 530ms (435+95.5) within Time::Local::_daygm which was called 79857 times, avg 7µs/call:
# 59892 times (310ms+69.8ms) by Time::Local::_timegm at line 94, avg 6µs/call
# 19964 times (124ms+25.7ms) by Time::Local::timegm at line 122, avg 8µs/call
# once (29µs+5µs) by Archive::Zip::Member::BEGIN@21 at line 65 | ||||
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 | 80109 | 643ms | 79857 | 95.5ms | $Cheat{ pack( 'ss', @_[ 4, 5 ] ) } ||= do { # spent 95.5ms making 79857 calls to Time::Local::CORE:pack, avg 1µs/call |
76 | my $month = ( $_[4] + 10 ) % 12; | ||||
77 | my $year = $_[5] + 1900 - int($month / 10); | ||||
78 | |||||
79 | ( ( 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 | # spent 770ms (390+380) within Time::Local::_timegm which was called 59892 times, avg 13µs/call:
# 19964 times (134ms+130ms) by Time::Local::timelocal at line 156, avg 13µs/call
# 19964 times (132ms+125ms) by Time::Local::timelocal at line 170, avg 13µs/call
# 19964 times (125ms+125ms) by Time::Local::timelocal at line 165, avg 12µs/call | ||||
91 | 119784 | 364ms | my $sec = | ||
92 | $SecOff + $_[0] + ( SECS_PER_MINUTE * $_[1] ) + ( SECS_PER_HOUR * $_[2] ); | ||||
93 | |||||
94 | 59892 | 380ms | return $sec + ( SECS_PER_DAY * &_daygm ); # spent 380ms making 59892 calls to Time::Local::_daygm, avg 6µs/call | ||
95 | } | ||||
96 | |||||
97 | # spent 446ms (296+150) within Time::Local::timegm which was called 19964 times, avg 22µs/call:
# 19964 times (296ms+150ms) by Time::Local::timelocal at line 155, avg 22µs/call | ||||
98 | 259532 | 295ms | my ( $sec, $min, $hour, $mday, $month, $year ) = @_; | ||
99 | |||||
100 | if ( $year >= 1000 ) { | ||||
101 | $year -= 1900; | ||||
102 | } | ||||
103 | elsif ( $year < 100 and $year >= 0 ) { | ||||
104 | $year += ( $year > $Breakpoint ) ? $Century : $NextCentury; | ||||
105 | } | ||||
106 | |||||
107 | unless ( $Options{no_range_check} ) { | ||||
108 | croak "Month '$month' out of range 0..11" | ||||
109 | if $month > 11 | ||||
110 | or $month < 0; | ||||
111 | |||||
112 | my $md = $MonthDays[$month]; | ||||
113 | 80 | 261µs | ++$md # spent 261µs making 80 calls to Time::Local::_is_leap_year, avg 3µs/call | ||
114 | if $month == 1 && _is_leap_year( $year + 1900 ); | ||||
115 | |||||
116 | croak "Day '$mday' out of range 1..$md" if $mday > $md or $mday < 1; | ||||
117 | croak "Hour '$hour' out of range 0..23" if $hour > 23 or $hour < 0; | ||||
118 | croak "Minute '$min' out of range 0..59" if $min > 59 or $min < 0; | ||||
119 | croak "Second '$sec' out of range 0..59" if $sec > 59 or $sec < 0; | ||||
120 | } | ||||
121 | |||||
122 | 19964 | 150ms | my $days = _daygm( undef, undef, undef, $mday, $month, $year ); # spent 150ms making 19964 calls to Time::Local::_daygm, avg 8µs/call | ||
123 | |||||
124 | 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 | return $sec | ||||
135 | + $SecOff | ||||
136 | + ( SECS_PER_MINUTE * $min ) | ||||
137 | + ( SECS_PER_HOUR * $hour ) | ||||
138 | + ( SECS_PER_DAY * $days ); | ||||
139 | } | ||||
140 | |||||
141 | # spent 261µs within Time::Local::_is_leap_year which was called 80 times, avg 3µs/call:
# 80 times (261µs+0s) by Time::Local::timegm at line 113, avg 3µs/call | ||||
142 | 136 | 477µs | 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 | # spent 2.16s (942ms+1.22) within Time::Local::timelocal which was called 19964 times, avg 108µs/call:
# 19964 times (942ms+1.22s) by Archive::Zip::Member::_dosToUnixTime at line 595 of Archive/Zip/Member.pm, avg 108µs/call | ||||
155 | 219604 | 885ms | 19964 | 446ms | my $ref_t = &timegm; # spent 446ms making 19964 calls to Time::Local::timegm, avg 22µs/call |
156 | 19964 | 264ms | my $loc_for_ref_t = _timegm( localtime($ref_t) ); # spent 264ms making 19964 calls to Time::Local::_timegm, avg 13µs/call | ||
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 | 19964 | 250ms | my $dst_off = $ref_t - _timegm( localtime($loc_t) ); # spent 250ms making 19964 calls to Time::Local::_timegm, avg 12µs/call | ||
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 | 19964 | 257ms | if ( ! $dst_off && # spent 257ms making 19964 calls to Time::Local::_timegm, avg 13µs/call | ||
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 | 104µs | 1; | ||
195 | |||||
196 | __END__ | ||||
# spent 95.5ms within Time::Local::CORE:pack which was called 79857 times, avg 1µs/call:
# 79857 times (95.5ms+0s) by Time::Local::_daygm at line 75, avg 1µs/call |