Profile of Time/Local.pm

← Index
NYTProf Performance Profile «block view•line view•sub view»
For xt/tapper-mcp-scheduler-with-db-longrun.t
Run on Tue May 22 17:18:39 2012
Reported on Tue May 22 17:22:37 2012

Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/5.12.3/Time/Local.pm
Statements | Executed 44 statements in 888µs

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