← Index
NYTProf Performance Profile   « line view »
For svc/members/upsert
  Run on Tue Jan 13 11:50:22 2015
Reported on Tue Jan 13 12:09:49 2015

Filename/usr/share/perl/5.20/Time/Local.pm
StatementsExecuted 69 statements in 1.10ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
32128µs34µsTime::Local::::_daygmTime::Local::_daygm
21121µs40µsTime::Local::::timegmTime::Local::timegm
11114µs45µsTime::Local::::BEGIN@4Time::Local::BEGIN@4
1119µs20µsTime::Local::::BEGIN@5Time::Local::BEGIN@5
1117µs40µsTime::Local::::BEGIN@27Time::Local::BEGIN@27
1116µs27µsTime::Local::::BEGIN@28Time::Local::BEGIN@28
3116µs6µsTime::Local::::CORE:packTime::Local::CORE:pack (opcode)
1115µs23µsTime::Local::::BEGIN@29Time::Local::BEGIN@29
1115µs50µsTime::Local::::BEGIN@8Time::Local::BEGIN@8
1115µs14µsTime::Local::::BEGIN@6Time::Local::BEGIN@6
0000s0sTime::Local::::_is_leap_yearTime::Local::_is_leap_year
0000s0sTime::Local::::_timegmTime::Local::_timegm
0000s0sTime::Local::::timegm_nocheckTime::Local::timegm_nocheck
0000s0sTime::Local::::timelocalTime::Local::timelocal
0000s0sTime::Local::::timelocal_nocheckTime::Local::timelocal_nocheck
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Time::Local;
2
311µsrequire Exporter;
4223µs276µs
# spent 45µs (14+31) within Time::Local::BEGIN@4 which was called: # once (14µs+31µs) by Date::Parse::BEGIN@10 at line 4
use Carp;
# spent 45µs making 1 call to Time::Local::BEGIN@4 # spent 31µs making 1 call to Exporter::import
5225µs231µs
# spent 20µs (9+11) within Time::Local::BEGIN@5 which was called: # once (9µs+11µs) by Date::Parse::BEGIN@10 at line 5
use Config;
# spent 20µs making 1 call to Time::Local::BEGIN@5 # spent 11µs making 1 call to Config::import
6222µs223µs
# spent 14µs (5+9) within Time::Local::BEGIN@6 which was called: # once (5µs+9µs) by Date::Parse::BEGIN@10 at line 6
use strict;
# spent 14µs making 1 call to Time::Local::BEGIN@6 # spent 9µs making 1 call to strict::import
7
8293µs294µs
# spent 50µs (5+44) within Time::Local::BEGIN@8 which was called: # once (5µs+44µs) by Date::Parse::BEGIN@10 at line 8
use vars qw( $VERSION @ISA @EXPORT @EXPORT_OK );
# spent 50µs making 1 call to Time::Local::BEGIN@8 # spent 44µs making 1 call to vars::import
91500ns$VERSION = '1.2300';
10
1117µs@ISA = qw( Exporter );
121400ns@EXPORT = qw( timegm timelocal );
131300ns@EXPORT_OK = qw( timegm_nocheck timelocal_nocheck );
14
151900nsmy @MonthDays = ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
16
17# Determine breakpoint for rolling century
1819µsmy $ThisYear = ( localtime() )[5];
1911µsmy $Breakpoint = ( $ThisYear + 50 ) % 100;
201700nsmy $NextCentury = $ThisYear - $ThisYear % 100;
211200ns$NextCentury += 100 if $Breakpoint < 50;
221200nsmy $Century = $NextCentury - 100;
231100nsmy $SecOff = 0;
24
251100nsmy ( %Options, %Cheat );
26
27224µs274µs
# spent 40µs (7+34) within Time::Local::BEGIN@27 which was called: # once (7µs+34µs) by Date::Parse::BEGIN@10 at line 27
use constant SECS_PER_MINUTE => 60;
# spent 40µs making 1 call to Time::Local::BEGIN@27 # spent 34µs making 1 call to constant::import
28221µs248µs
# spent 27µs (6+21) within Time::Local::BEGIN@28 which was called: # once (6µs+21µs) by Date::Parse::BEGIN@10 at line 28
use constant SECS_PER_HOUR => 3600;
# spent 27µs making 1 call to Time::Local::BEGIN@28 # spent 21µs making 1 call to constant::import
292784µs241µs
# spent 23µs (5+18) within Time::Local::BEGIN@29 which was called: # once (5µs+18µs) by Date::Parse::BEGIN@10 at line 29
use constant SECS_PER_DAY => 86400;
# spent 23µs making 1 call to Time::Local::BEGIN@29 # spent 18µs making 1 call to constant::import
30
31my $MaxDay;
321900nsif ($] < 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}
44else {
45 # recent localtime()'s limit is the year 2**31
461300ns $MaxDay = 365 * (2**31);
47}
48
49# Determine the EPOC day for this machine
501100nsmy $Epoc = 0;
5112µsif ( $^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}
56elsif ( $^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}
64else {
6518µs116µs $Epoc = _daygm( gmtime(0) );
# spent 16µs making 1 call to Time::Local::_daygm
66}
67
681700ns%Cheat = (); # clear the cache as epoc has changed
69
70
# spent 34µs (28+6) within Time::Local::_daygm which was called 3 times, avg 11µs/call: # 2 times (15µs+3µs) by Time::Local::timegm at line 122, avg 9µs/call # once (13µs+3µs) by Date::Parse::BEGIN@10 at line 65
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] + (
75331µs36µs $Cheat{ pack( 'ss', @_[ 4, 5 ] ) } ||= do {
# spent 6µs making 3 calls to Time::Local::CORE:pack, avg 2µs/call
7622µs my $month = ( $_[4] + 10 ) % 12;
7723µs my $year = $_[5] + 1900 - int($month / 10);
78
7924µ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
90sub _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 40µs (21+18) within Time::Local::timegm which was called 2 times, avg 20µs/call: # 2 times (21µs+18µs) by Set::Infinite::BEGIN@18 at line 32 of Set/Infinite/Arithmetic.pm, avg 20µs/call
sub timegm {
9821µs my ( $sec, $min, $hour, $mday, $month, $year ) = @_;
99
10022µs if ( $year >= 1000 ) {
101 $year -= 1900;
102 }
103 elsif ( $year < 100 and $year >= 0 ) {
104 $year += ( $year > $Breakpoint ) ? $Century : $NextCentury;
105 }
106
10721µs unless ( $Options{no_range_check} ) {
10821µs croak "Month '$month' out of range 0..11"
109 if $month > 11
110 or $month < 0;
111
1122900ns my $md = $MonthDays[$month];
1132500ns ++$md
114 if $month == 1 && _is_leap_year( $year + 1900 );
115
1162800ns croak "Day '$mday' out of range 1..$md" if $mday > $md or $mday < 1;
1172600ns croak "Hour '$hour' out of range 0..23" if $hour > 23 or $hour < 0;
1182600ns croak "Minute '$min' out of range 0..59" if $min > 59 or $min < 0;
1192900ns croak "Second '$sec' out of range 0..59" if $sec >= 60 or $sec < 0;
120 }
121
12223µs218µs my $days = _daygm( undef, undef, undef, $mday, $month, $year );
# spent 18µs making 2 calls to Time::Local::_daygm, avg 9µs/call
123
12421µs 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
13425µs return $sec
135 + $SecOff
136 + ( SECS_PER_MINUTE * $min )
137 + ( SECS_PER_HOUR * $hour )
138 + ( SECS_PER_DAY * $days );
139}
140
141sub _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
149sub timegm_nocheck {
150 local $Options{no_range_check} = 1;
151 return &timegm;
152}
153
154sub 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
189sub timelocal_nocheck {
190 local $Options{no_range_check} = 1;
191 return &timelocal;
192}
193
194111µs1;
195
196__END__
 
# spent 6µs within Time::Local::CORE:pack which was called 3 times, avg 2µs/call: # 3 times (6µs+0s) by Time::Local::_daygm at line 75, avg 2µs/call
sub Time::Local::CORE:pack; # opcode