Filename | /usr/share/perl/5.10/Time/Local.pm |
Statements | Executed 81 statements in 1.58ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 157µs | 161µs | BEGIN@7 | Time::Local::
1 | 1 | 1 | 65µs | 69µs | BEGIN@6 | Time::Local::
2 | 1 | 1 | 35µs | 61µs | timegm | Time::Local::
3 | 2 | 1 | 35µs | 44µs | _daygm | Time::Local::
1 | 1 | 1 | 22µs | 104µs | BEGIN@4 | Time::Local::
1 | 1 | 1 | 16µs | 36µs | BEGIN@5 | Time::Local::
1 | 1 | 1 | 13µs | 80µs | BEGIN@28 | Time::Local::
1 | 1 | 1 | 13µs | 119µs | BEGIN@9 | Time::Local::
1 | 1 | 1 | 10µs | 47µs | BEGIN@30 | Time::Local::
3 | 1 | 1 | 9µs | 9µs | CORE:pack (opcode) | Time::Local::
1 | 1 | 1 | 9µs | 42µ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 | 1µs | require Exporter; | ||
4 | 3 | 36µs | 2 | 186µs | # spent 104µs (22+82) within Time::Local::BEGIN@4 which was called:
# once (22µs+82µs) by LWP::UserAgent::BEGIN@12 at line 4 # spent 104µs making 1 call to Time::Local::BEGIN@4
# spent 82µs making 1 call to Exporter::import |
5 | 3 | 33µs | 2 | 56µs | # spent 36µs (16+20) within Time::Local::BEGIN@5 which was called:
# once (16µs+20µs) by LWP::UserAgent::BEGIN@12 at line 5 # spent 36µs making 1 call to Time::Local::BEGIN@5
# spent 20µs making 1 call to Config::import |
6 | 3 | 55µs | 2 | 74µs | # spent 69µs (65+4) within Time::Local::BEGIN@6 which was called:
# once (65µs+4µs) by LWP::UserAgent::BEGIN@12 at line 6 # spent 69µs making 1 call to Time::Local::BEGIN@6
# spent 4µs making 1 call to strict::import |
7 | 3 | 175µs | 2 | 165µs | # spent 161µs (157+4) within Time::Local::BEGIN@7 which was called:
# once (157µs+4µs) by LWP::UserAgent::BEGIN@12 at line 7 # spent 161µs making 1 call to Time::Local::BEGIN@7
# spent 4µs making 1 call to integer::import |
8 | |||||
9 | 3 | 121µs | 2 | 225µs | # spent 119µs (13+106) within Time::Local::BEGIN@9 which was called:
# once (13µs+106µs) by LWP::UserAgent::BEGIN@12 at line 9 # spent 119µs making 1 call to Time::Local::BEGIN@9
# spent 106µs making 1 call to vars::import |
10 | 1 | 600ns | $VERSION = '1.1901'; | ||
11 | |||||
12 | 1 | 12µs | @ISA = qw( Exporter ); | ||
13 | 1 | 900ns | @EXPORT = qw( timegm timelocal ); | ||
14 | 1 | 1µs | @EXPORT_OK = qw( timegm_nocheck timelocal_nocheck ); | ||
15 | |||||
16 | 1 | 1µs | my @MonthDays = ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ); | ||
17 | |||||
18 | # Determine breakpoint for rolling century | ||||
19 | 1 | 37µs | my $ThisYear = ( localtime() )[5]; | ||
20 | 1 | 3µs | my $Breakpoint = ( $ThisYear + 50 ) % 100; | ||
21 | 1 | 800ns | my $NextCentury = $ThisYear - $ThisYear % 100; | ||
22 | 1 | 600ns | $NextCentury += 100 if $Breakpoint < 50; | ||
23 | 1 | 300ns | my $Century = $NextCentury - 100; | ||
24 | 1 | 200ns | my $SecOff = 0; | ||
25 | |||||
26 | 1 | 700ns | my ( %Options, %Cheat ); | ||
27 | |||||
28 | 3 | 42µs | 2 | 147µs | # spent 80µs (13+67) within Time::Local::BEGIN@28 which was called:
# once (13µs+67µs) by LWP::UserAgent::BEGIN@12 at line 28 # spent 80µs making 1 call to Time::Local::BEGIN@28
# spent 67µs making 1 call to constant::import |
29 | 3 | 171µs | 2 | 76µs | # spent 42µs (9+33) within Time::Local::BEGIN@29 which was called:
# once (9µs+33µs) by LWP::UserAgent::BEGIN@12 at line 29 # spent 42µs making 1 call to Time::Local::BEGIN@29
# spent 33µs making 1 call to constant::import |
30 | 3 | 754µs | 2 | 83µs | # spent 47µs (10+36) within Time::Local::BEGIN@30 which was called:
# once (10µs+36µs) by LWP::UserAgent::BEGIN@12 at line 30 # spent 47µs making 1 call to Time::Local::BEGIN@30
# spent 36µs making 1 call to constant::import |
31 | |||||
32 | 1 | 300ns | my $MaxInt; | ||
33 | 1 | 4µs | if ( $^O eq 'MacOS' ) { | ||
34 | # time_t is unsigned... | ||||
35 | $MaxInt = ( 1 << ( 8 * $Config{ivsize} ) ) - 1; | ||||
36 | } | ||||
37 | else { | ||||
38 | 1 | 15µs | 1 | 69µs | $MaxInt = ( ( 1 << ( 8 * $Config{ivsize} - 2 ) ) - 1 ) * 2 + 1; # spent 69µ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 | 500ns | my $Epoc = 0; | ||
45 | 1 | 2µ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 | 6µs | 1 | 18µs | $Epoc = _daygm( gmtime(0) ); # spent 18µ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 | 3 | 40µ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 | 2 | 2µs | my $month = ( $_[4] + 10 ) % 12; | ||
71 | 2 | 2µs | my $year = ( $_[5] + 1900 ) - ( $month / 10 ); | ||
72 | |||||
73 | 2 | 3µs | ( ( 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 61µs (35+26) within Time::Local::timegm which was called 2 times, avg 31µs/call:
# 2 times (35µs+26µs) by Set::Infinite::BEGIN@18 at line 32 of Set/Infinite/Arithmetic.pm, avg 31µs/call | ||||
92 | 2 | 3µs | my ( $sec, $min, $hour, $mday, $month, $year ) = @_; | ||
93 | |||||
94 | 2 | 2µs | if ( $year >= 1000 ) { | ||
95 | $year -= 1900; | ||||
96 | } | ||||
97 | elsif ( $year < 100 and $year >= 0 ) { | ||||
98 | $year += ( $year > $Breakpoint ) ? $Century : $NextCentury; | ||||
99 | } | ||||
100 | |||||
101 | 2 | 2µs | unless ( $Options{no_range_check} ) { | ||
102 | 2 | 2µs | croak "Month '$month' out of range 0..11" | ||
103 | if $month > 11 | ||||
104 | or $month < 0; | ||||
105 | |||||
106 | 2 | 2µs | my $md = $MonthDays[$month]; | ||
107 | 2 | 1µs | ++$md | ||
108 | if $month == 1 && _is_leap_year( $year + 1900 ); | ||||
109 | |||||
110 | 2 | 1µs | croak "Day '$mday' out of range 1..$md" if $mday > $md or $mday < 1; | ||
111 | 2 | 1µs | croak "Hour '$hour' out of range 0..23" if $hour > 23 or $hour < 0; | ||
112 | 2 | 800ns | croak "Minute '$min' out of range 0..59" if $min > 59 or $min < 0; | ||
113 | 2 | 1µs | croak "Second '$sec' out of range 0..59" if $sec > 59 or $sec < 0; | ||
114 | } | ||||
115 | |||||
116 | 2 | 5µs | 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 | 2 | 2µs | 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 | 2 | 8µs | 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 | 22µ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 |