| Filename | /usr/local/share/perl/5.18.2/POSIX/strftime/Compiler.pm |
| Statements | Executed 68 statements in 2.64ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 985µs | 1.25ms | POSIX::strftime::Compiler::BEGIN@7 |
| 1 | 1 | 1 | 539µs | 580µs | POSIX::strftime::Compiler::compile |
| 1 | 1 | 1 | 53µs | 53µs | POSIX::strftime::Compiler::BEGIN@29 |
| 1 | 1 | 1 | 28µs | 700µs | POSIX::strftime::Compiler::strftime |
| 1 | 1 | 1 | 18µs | 18µs | POSIX::strftime::Compiler::__ANON__[:293] |
| 1 | 1 | 1 | 15µs | 15µs | POSIX::strftime::Compiler::BEGIN@3 |
| 1 | 1 | 1 | 12µs | 124µs | POSIX::strftime::Compiler::BEGIN@14 |
| 4 | 3 | 1 | 11µs | 11µs | POSIX::strftime::Compiler::CORE:match (opcode) |
| 1 | 1 | 1 | 10µs | 73µs | POSIX::strftime::Compiler::BEGIN@9 |
| 4 | 4 | 1 | 9µs | 9µs | POSIX::strftime::Compiler::CORE:subst (opcode) |
| 1 | 1 | 1 | 6µs | 18µs | POSIX::strftime::Compiler::BEGIN@34 |
| 1 | 1 | 1 | 6µs | 10µs | POSIX::strftime::Compiler::BEGIN@5 |
| 1 | 1 | 1 | 6µs | 34µs | POSIX::strftime::Compiler::BEGIN@6 |
| 1 | 1 | 1 | 5µs | 14µs | POSIX::strftime::Compiler::BEGIN@4 |
| 1 | 1 | 1 | 4µs | 4µs | POSIX::strftime::Compiler::BEGIN@8 |
| 2 | 1 | 1 | 4µs | 4µs | POSIX::strftime::Compiler::CORE:substcont (opcode) |
| 0 | 0 | 0 | 0s | 0s | POSIX::strftime::Compiler::__ANON__[:283] |
| 0 | 0 | 0 | 0s | 0s | POSIX::strftime::Compiler::_tzname |
| 0 | 0 | 0 | 0s | 0s | POSIX::strftime::Compiler::_tzoffset |
| 0 | 0 | 0 | 0s | 0s | POSIX::strftime::Compiler::code_ref |
| 0 | 0 | 0 | 0s | 0s | POSIX::strftime::Compiler::isleap |
| 0 | 0 | 0 | 0s | 0s | POSIX::strftime::Compiler::iso_week_days |
| 0 | 0 | 0 | 0s | 0s | POSIX::strftime::Compiler::isodaysnum |
| 0 | 0 | 0 | 0s | 0s | POSIX::strftime::Compiler::isoweeknum |
| 0 | 0 | 0 | 0s | 0s | POSIX::strftime::Compiler::isoyearnum |
| 0 | 0 | 0 | 0s | 0s | POSIX::strftime::Compiler::new |
| 0 | 0 | 0 | 0s | 0s | POSIX::strftime::Compiler::to_string |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package POSIX::strftime::Compiler; | ||||
| 2 | |||||
| 3 | 2 | 36µs | 1 | 15µs | # spent 15µs within POSIX::strftime::Compiler::BEGIN@3 which was called:
# once (15µs+0s) by Apache::LogFormat::Compiler::BEGIN@7 at line 3 # spent 15µs making 1 call to POSIX::strftime::Compiler::BEGIN@3 |
| 4 | 2 | 17µs | 2 | 24µs | # spent 14µs (5+9) within POSIX::strftime::Compiler::BEGIN@4 which was called:
# once (5µs+9µs) by Apache::LogFormat::Compiler::BEGIN@7 at line 4 # spent 14µs making 1 call to POSIX::strftime::Compiler::BEGIN@4
# spent 9µs making 1 call to strict::import |
| 5 | 2 | 17µs | 2 | 13µs | # spent 10µs (6+4) within POSIX::strftime::Compiler::BEGIN@5 which was called:
# once (6µs+4µs) by Apache::LogFormat::Compiler::BEGIN@7 at line 5 # spent 10µs making 1 call to POSIX::strftime::Compiler::BEGIN@5
# spent 4µs making 1 call to warnings::import |
| 6 | 2 | 22µs | 2 | 62µs | # spent 34µs (6+28) within POSIX::strftime::Compiler::BEGIN@6 which was called:
# once (6µs+28µs) by Apache::LogFormat::Compiler::BEGIN@7 at line 6 # spent 34µs making 1 call to POSIX::strftime::Compiler::BEGIN@6
# spent 28µs making 1 call to Exporter::import |
| 7 | 2 | 160µs | 1 | 1.25ms | # spent 1.25ms (985µs+266µs) within POSIX::strftime::Compiler::BEGIN@7 which was called:
# once (985µs+266µs) by Apache::LogFormat::Compiler::BEGIN@7 at line 7 # spent 1.25ms making 1 call to POSIX::strftime::Compiler::BEGIN@7 |
| 8 | 2 | 20µs | 1 | 4µs | # spent 4µs within POSIX::strftime::Compiler::BEGIN@8 which was called:
# once (4µs+0s) by Apache::LogFormat::Compiler::BEGIN@7 at line 8 # spent 4µs making 1 call to POSIX::strftime::Compiler::BEGIN@8 |
| 9 | 2 | 72µs | 2 | 136µs | # spent 73µs (10+63) within POSIX::strftime::Compiler::BEGIN@9 which was called:
# once (10µs+63µs) by Apache::LogFormat::Compiler::BEGIN@7 at line 9 # spent 73µs making 1 call to POSIX::strftime::Compiler::BEGIN@9
# spent 63µs making 1 call to base::import |
| 10 | |||||
| 11 | 1 | 400ns | our $VERSION = "0.32"; | ||
| 12 | 1 | 800ns | our @EXPORT_OK = qw/strftime/; | ||
| 13 | |||||
| 14 | # spent 124µs (12+111) within POSIX::strftime::Compiler::BEGIN@14 which was called:
# once (12µs+111µs) by Apache::LogFormat::Compiler::BEGIN@7 at line 27 | ||||
| 15 | 1 | 10µs | 1 | 111µs | SEC => 0, # spent 111µs making 1 call to constant::import |
| 16 | MIN => 1, | ||||
| 17 | HOUR => 2, | ||||
| 18 | DAY => 3, | ||||
| 19 | MONTH => 4, | ||||
| 20 | YEAR => 5, | ||||
| 21 | WDAY => 6, | ||||
| 22 | YDAY => 7, | ||||
| 23 | ISDST => 8, | ||||
| 24 | ISO_WEEK_START_WDAY => 1, # Monday | ||||
| 25 | ISO_WEEK1_WDAY => 4, # Thursday | ||||
| 26 | YDAY_MINIMUM => -366, | ||||
| 27 | 1 | 47µs | 1 | 124µs | }; # spent 124µs making 1 call to POSIX::strftime::Compiler::BEGIN@14 |
| 28 | |||||
| 29 | # spent 53µs within POSIX::strftime::Compiler::BEGIN@29 which was called:
# once (53µs+0s) by Apache::LogFormat::Compiler::BEGIN@7 at line 37 | ||||
| 30 | 1 | 1µs | *tzoffset = \&_tzoffset; | ||
| 31 | 1 | 800ns | *tzname = \&_tzname; | ||
| 32 | |||||
| 33 | 2 | 52µs | if (eval { require Time::TZOffset; 1; }) { | ||
| 34 | 2 | 29µs | 2 | 30µs | # spent 18µs (6+12) within POSIX::strftime::Compiler::BEGIN@34 which was called:
# once (6µs+12µs) by Apache::LogFormat::Compiler::BEGIN@7 at line 34 # spent 18µs making 1 call to POSIX::strftime::Compiler::BEGIN@34
# spent 12µs making 1 call to warnings::unimport |
| 35 | *tzoffset = \&Time::TZOffset::tzoffset; | ||||
| 36 | } | ||||
| 37 | 1 | 1.39ms | 1 | 53µs | } # spent 53µs making 1 call to POSIX::strftime::Compiler::BEGIN@29 |
| 38 | |||||
| 39 | |||||
| 40 | # copy from POSIX/strftime/GNU/PP.pm and modify | ||||
| 41 | 1 | 39µs | my @offset2zone = qw( | ||
| 42 | -1100 0 SST -1100 0 SST | ||||
| 43 | -1000 0 HAST -0900 1 HADT | ||||
| 44 | -1000 0 HST -1000 0 HST | ||||
| 45 | -0930 0 MART -0930 0 MART | ||||
| 46 | -0900 0 AKST -0800 1 AKDT | ||||
| 47 | -0900 0 GAMT -0900 0 GAMT | ||||
| 48 | -0800 0 PST -0700 1 PDT | ||||
| 49 | -0800 0 PST -0800 0 PST | ||||
| 50 | -0700 0 MST -0600 1 MDT | ||||
| 51 | -0700 0 MST -0700 0 MST | ||||
| 52 | -0600 0 CST -0500 1 CDT | ||||
| 53 | -0600 0 GALT -0600 0 GALT | ||||
| 54 | -0500 0 ECT -0500 0 ECT | ||||
| 55 | -0500 0 EST -0400 1 EDT | ||||
| 56 | -0500 1 EASST -0600 0 EAST | ||||
| 57 | -0430 0 VET -0430 0 VET | ||||
| 58 | -0400 0 AMT -0400 0 AMT | ||||
| 59 | -0400 0 AST -0300 1 ADT | ||||
| 60 | -0330 0 NST -0230 1 NDT | ||||
| 61 | -0300 0 ART -0300 0 ART | ||||
| 62 | -0300 0 PMST -0200 1 PMDT | ||||
| 63 | -0300 1 AMST -0400 0 AMT | ||||
| 64 | -0300 1 WARST -0300 1 WARST | ||||
| 65 | -0200 0 FNT -0200 0 FNT | ||||
| 66 | -0200 1 UYST -0300 0 UYT | ||||
| 67 | -0100 0 AZOT +0000 1 AZOST | ||||
| 68 | -0100 0 CVT -0100 0 CVT | ||||
| 69 | +0000 0 GMT +0000 0 GMT | ||||
| 70 | +0000 0 WET +0100 1 WEST | ||||
| 71 | +0100 0 CET +0200 1 CEST | ||||
| 72 | +0100 0 WAT +0100 0 WAT | ||||
| 73 | +0200 0 EET +0200 0 EET | ||||
| 74 | +0200 0 IST +0300 1 IDT | ||||
| 75 | +0200 1 WAST +0100 0 WAT | ||||
| 76 | +0300 0 FET +0300 0 FET | ||||
| 77 | +030704 0 zzz +030704 0 zzz | ||||
| 78 | +0330 0 IRST +0430 1 IRDT | ||||
| 79 | +0400 0 AZT +0500 1 AZST | ||||
| 80 | +0400 0 GST +0400 0 GST | ||||
| 81 | +0430 0 AFT +0430 0 AFT | ||||
| 82 | +0500 0 DAVT +0700 0 DAVT | ||||
| 83 | +0500 0 MVT +0500 0 MVT | ||||
| 84 | +0530 0 IST +0530 0 IST | ||||
| 85 | +0545 0 NPT +0545 0 NPT | ||||
| 86 | +0600 0 BDT +0600 0 BDT | ||||
| 87 | +0630 0 CCT +0630 0 CCT | ||||
| 88 | +0700 0 ICT +0700 0 ICT | ||||
| 89 | +0800 0 HKT +0800 0 HKT | ||||
| 90 | +0845 0 CWST +0845 0 CWST | ||||
| 91 | +0900 0 JST +0900 0 JST | ||||
| 92 | +0930 0 CST +0930 0 CST | ||||
| 93 | +1000 0 PGT +1000 0 PGT | ||||
| 94 | +1030 1 CST +0930 0 CST | ||||
| 95 | +1100 0 CAST +0800 0 WST | ||||
| 96 | +1100 0 NCT +1100 0 NCT | ||||
| 97 | +1100 1 EST +1000 0 EST | ||||
| 98 | +1100 1 LHST +1030 0 LHST | ||||
| 99 | +1130 0 NFT +1130 0 NFT | ||||
| 100 | +1200 0 FJT +1200 0 FJT | ||||
| 101 | +1300 0 TKT +1300 0 TKT | ||||
| 102 | +1300 1 NZDT +1200 0 NZST | ||||
| 103 | +1345 1 CHADT +1245 0 CHAST | ||||
| 104 | +1400 0 LINT +1400 0 LINT | ||||
| 105 | +1400 1 WSDT +1300 0 WST | ||||
| 106 | ); | ||||
| 107 | |||||
| 108 | sub _tzoffset { | ||||
| 109 | my $diff = (exists $ENV{TZ} and $ENV{TZ} =~ m!^(?:GMT|UTC)$!) | ||||
| 110 | ? 0 | ||||
| 111 | : Time::Local::timegm(@_) - Time::Local::timelocal(@_); | ||||
| 112 | sprintf '%+03d%02u', $diff/60/60, $diff/60%60; | ||||
| 113 | } | ||||
| 114 | |||||
| 115 | sub _tzname { | ||||
| 116 | return $ENV{TZ} if exists $ENV{TZ} and $ENV{TZ} =~ m!^(?:GMT|UTC)$!; | ||||
| 117 | |||||
| 118 | my $diff = tzoffset(@_); | ||||
| 119 | |||||
| 120 | my @t1 = my @t2 = @_; | ||||
| 121 | @t1[3,4] = (1, 1); # winter | ||||
| 122 | my $diff1 = tzoffset(@t1); | ||||
| 123 | @t2[3,4] = (1, 7); # summer | ||||
| 124 | my $diff2 = tzoffset(@t2); | ||||
| 125 | |||||
| 126 | for (my $i=0; $i < @offset2zone; $i += 6) { | ||||
| 127 | next unless $offset2zone[$i] eq $diff1 and $offset2zone[$i+3] eq $diff2; | ||||
| 128 | return $diff2 eq $diff ? $offset2zone[$i+5] : $offset2zone[$i+2]; | ||||
| 129 | } | ||||
| 130 | |||||
| 131 | if ($diff =~ /^([+-])(\d\d)$/) { | ||||
| 132 | return sprintf 'GMT%s%d', $1 eq '-' ? '+' : '-', $2; | ||||
| 133 | }; | ||||
| 134 | |||||
| 135 | return 'Etc'; | ||||
| 136 | } | ||||
| 137 | |||||
| 138 | sub iso_week_days { | ||||
| 139 | my ($yday, $wday) = @_; | ||||
| 140 | |||||
| 141 | # Add enough to the first operand of % to make it nonnegative. | ||||
| 142 | my $big_enough_multiple_of_7 = (int(- YDAY_MINIMUM / 7) + 2) * 7; | ||||
| 143 | return ($yday | ||||
| 144 | - ($yday - $wday + ISO_WEEK1_WDAY + $big_enough_multiple_of_7) % 7 | ||||
| 145 | + ISO_WEEK1_WDAY - ISO_WEEK_START_WDAY); | ||||
| 146 | } | ||||
| 147 | |||||
| 148 | sub isleap { | ||||
| 149 | my $year = shift; | ||||
| 150 | return ($year % 4 == 0 && ($year % 100 != 0 || $year % 400 == 0)) ? 1 : 0 | ||||
| 151 | } | ||||
| 152 | |||||
| 153 | sub isodaysnum { | ||||
| 154 | my @t = @_; | ||||
| 155 | |||||
| 156 | my $year = ($t[YEAR] + ($t[YEAR] < 0 ? 1900 % 400 : 1900 % 400 - 400)); | ||||
| 157 | my $year_adjust = 0; | ||||
| 158 | my $days = iso_week_days($t[YDAY], $t[WDAY]); | ||||
| 159 | |||||
| 160 | if ($days < 0) { | ||||
| 161 | # This ISO week belongs to the previous year. | ||||
| 162 | $year_adjust = -1; | ||||
| 163 | $days = iso_week_days($t[YDAY] + (365 + isleap($year -1)), $t[WDAY]); | ||||
| 164 | } | ||||
| 165 | else { | ||||
| 166 | my $d = iso_week_days($t[YDAY] - (365 + isleap($year)), $t[WDAY]); | ||||
| 167 | if ($d >= 0) { | ||||
| 168 | # This ISO week belongs to the next year. */ | ||||
| 169 | $year_adjust = 1; | ||||
| 170 | $days = $d; | ||||
| 171 | } | ||||
| 172 | } | ||||
| 173 | |||||
| 174 | return ($days, $year_adjust); | ||||
| 175 | } | ||||
| 176 | |||||
| 177 | sub isoyearnum { | ||||
| 178 | my ($days, $year_adjust) = isodaysnum(@_); | ||||
| 179 | return $_[YEAR] + 1900 + $year_adjust; | ||||
| 180 | } | ||||
| 181 | |||||
| 182 | sub isoweeknum { | ||||
| 183 | my ($days, $year_adjust) = isodaysnum(@_); | ||||
| 184 | return int($days / 7) + 1; | ||||
| 185 | } | ||||
| 186 | |||||
| 187 | 1 | 37µs | our %FORMAT_CHARS = map { $_ => 1 } split //, q!%aAbBcCdDeFGghHIjklmMnNpPrRsStTuUVwWxXyYzZ!; | ||
| 188 | |||||
| 189 | 1 | 18µs | our %SPRINTF_CHARS = ( | ||
| 190 | '%' => [q!%s!, q!%!], | ||||
| 191 | 'a' => [q!%s!, q!$weekday_abbr[$_[WDAY]]!], | ||||
| 192 | 'A' => [q!%s!, q!$weekday_name[$_[WDAY]]!], | ||||
| 193 | 'b' => [q!%s!, q!$month_abbr[$_[MONTH]]!], | ||||
| 194 | 'B' => [q!%s!, q!$month_name[$_[MONTH]]!], | ||||
| 195 | 'c' => [q!%s %s %2d %02d:%02d:%02d %04d!, | ||||
| 196 | q!$weekday_abbr[$_[WDAY]], $month_abbr[$_[MONTH]], $_[DAY], $_[HOUR], $_[MIN], $_[SEC], $_[YEAR]+1900!], | ||||
| 197 | 'C' => [q!%02d!, q!($_[YEAR]+1900)/100!], | ||||
| 198 | 'd' => [q!%02d!, q!$_[DAY]!], | ||||
| 199 | 'D' => [q!%02d/%02d/%02d!, q!$_[MONTH]+1,$_[DAY],$_[YEAR]%100!], | ||||
| 200 | 'e' => [q!%2d!, q!$_[DAY]!], | ||||
| 201 | 'F' => [q!%04d-%02d-%02d!, q!$_[YEAR]+1900,$_[MONTH]+1,$_[DAY]!], | ||||
| 202 | 'h' => [q!%s!, q!$month_abbr[$_[MONTH]]!], | ||||
| 203 | 'H' => [q!%02d!, q!$_[HOUR]!], | ||||
| 204 | 'I' => [q!%02d!, q!$_[HOUR]%12 || 1!], | ||||
| 205 | 'j' => [q!%03d!, q!$_[YDAY]+1!], | ||||
| 206 | 'k' => [q!%2d!, q!$_[HOUR]!], | ||||
| 207 | 'l' => [q!%2d!, q!$_[HOUR]%12 || 1!], | ||||
| 208 | 'm' => [q!%02d!, q!$_[MONTH]+1!], | ||||
| 209 | 'M' => [q!%02d!, q!$_[MIN]!], | ||||
| 210 | 'n' => [q!%s!, q!"\n"!], | ||||
| 211 | 'N' => [q!%s!, q!substr(sprintf('%.9f', $_[SEC] - int $_[SEC]), 2)!], | ||||
| 212 | 'p' => [q!%s!, q!$_[HOUR] > 0 && $_[HOUR] < 13 ? "AM" : "PM"!], | ||||
| 213 | 'P' => [q!%s!, q!$_[HOUR] > 0 && $_[HOUR] < 13 ? "am" : "pm"!], | ||||
| 214 | 'r' => [q!%02d:%02d:%02d %s!, q!$_[HOUR]%12 || 1, $_[MIN], $_[SEC], $_[HOUR] > 0 && $_[HOUR] < 13 ? "AM" : "PM"!], | ||||
| 215 | 'R' => [q!%02d:%02d!, q!$_[HOUR], $_[MIN]!], | ||||
| 216 | 'S' => [q!%02d!, q!$_[SEC]!], | ||||
| 217 | 't' => [q!%s!, q!"\t"!], | ||||
| 218 | 'T' => [q!%02d:%02d:%02d!, q!$_[HOUR], $_[MIN], $_[SEC]!], | ||||
| 219 | 'u' => [q!%d!, q!$_[WDAY] || 7!], | ||||
| 220 | 'w' => [q!%d!, q!$_[WDAY]!], | ||||
| 221 | 'x' => [q!%02d/%02d/%02d!, q!$_[MONTH]+1,$_[DAY],$_[YEAR]%100!], | ||||
| 222 | 'X' => [q!%02d:%02d:%02d!, q!$_[HOUR], $_[MIN], $_[SEC]!], | ||||
| 223 | 'y' => [q!%02d!, q!$_[YEAR]%100!], | ||||
| 224 | 'Y' => [q!%02d!, q!$_[YEAR]+1900!], | ||||
| 225 | '%' => [q!%s!, q!'%'!], | ||||
| 226 | ); | ||||
| 227 | |||||
| 228 | 2 | 25µs | if ( eval { require Time::TZOffset; 1 } ) { | ||
| 229 | $SPRINTF_CHARS{z} = [q!%s!,q!Time::TZOffset::tzoffset(@_)!]; | ||||
| 230 | } | ||||
| 231 | |||||
| 232 | 1 | 7µs | our %LOCALE_CHARS = ( | ||
| 233 | '%' => [q!'%%'!], | ||||
| 234 | 'a' => [q!$weekday_abbr[$_[WDAY]]!,1], | ||||
| 235 | 'A' => [q!$weekday_name[$_[WDAY]]!,1], | ||||
| 236 | 'b' => [q!$month_abbr[$_[MONTH]]!], | ||||
| 237 | 'B' => [q!$month_name[$_[MONTH]]!], | ||||
| 238 | 'c' => [q!$weekday_abbr[$_[WDAY]] . ' ' . $month_abbr[$_[MONTH]] . ' ' . substr(' '.$_[DAY],-2) . ' %H:%M:%S %Y'!,1], | ||||
| 239 | 'C' => [q!substr('0'.int(($_[YEAR]+1900)/100), -2)!], #century | ||||
| 240 | 'h' => [q!$month_abbr[$_[MONTH]]!], | ||||
| 241 | 'N' => [q!substr(sprintf('%.9f', $_[SEC] - int $_[SEC]), 2)!], | ||||
| 242 | 'n' => [q!"\n"!], | ||||
| 243 | 'p' => [q!$_[HOUR] > 0 && $_[HOUR] < 13 ? "AM" : "PM"!], | ||||
| 244 | 'P' => [q!$_[HOUR] > 0 && $_[HOUR] < 13 ? "am" : "pm"!], | ||||
| 245 | 'r' => [q!sprintf('%02d:%02d:%02d %s',$_[HOUR]%12 || 1, $_[MIN], $_[SEC], $_[HOUR] > 0 && $_[HOUR] < 13 ? "AM" : "PM")!], | ||||
| 246 | 't' => [q!"\t"!], | ||||
| 247 | 'x' => [q!'%m/%d/%y'!], | ||||
| 248 | 'X' => [q!'%H:%M:%S'!], | ||||
| 249 | 'z' => [q!'%z'!,1], | ||||
| 250 | 'Z' => [q!'%Z'!,1], | ||||
| 251 | ); | ||||
| 252 | |||||
| 253 | 1 | 9µs | 2 | 1µs | if ( $^O =~ m!^(MSWin32|cygwin)$!i ) { # spent 1µs making 2 calls to POSIX::strftime::Compiler::CORE:match, avg 700ns/call |
| 254 | %LOCALE_CHARS = ( | ||||
| 255 | %LOCALE_CHARS, | ||||
| 256 | 'D' => [q!'%m/%d/%y'!], | ||||
| 257 | 'F' => [q!'%Y-%m-%d'!], | ||||
| 258 | 'G' => [q!substr('0000'. isoyearnum(@_), -4)!,1], | ||||
| 259 | 'R' => [q!'%H:%M'!], | ||||
| 260 | 'T' => [q!'%H:%M:%S'!], | ||||
| 261 | 'V' => [q!substr('0'.isoweeknum(@_),-2)!,1], | ||||
| 262 | 'e' => [q!substr(' '.$_[DAY],-2)!], | ||||
| 263 | 'g' => [q!substr('0'.isoyearnum(@_)%100,-2)!,1], | ||||
| 264 | 'k' => [q!substr(' '.$_[HOUR],-2)!], | ||||
| 265 | 'l' => [q!substr(' '.($_[HOUR]%12 || 1),-2)!], | ||||
| 266 | 's' => [q!int(Time::Local::timegm(@_))!,1], | ||||
| 267 | 'u' => [q!$_[WDAY] || 7!,1], | ||||
| 268 | 'z' => [q!tzoffset(@_)!,1], | ||||
| 269 | 'Z' => [q!tzname(@_)!,1], | ||||
| 270 | ); | ||||
| 271 | } | ||||
| 272 | elsif ( $^O =~ m!^solaris$!i ) { | ||||
| 273 | $LOCALE_CHARS{s} = [q!int(Time::Local::timegm(@_))!,1]; | ||||
| 274 | } | ||||
| 275 | |||||
| 276 | my $sprintf_char_handler = sub { | ||||
| 277 | my ($char,$args) = @_; | ||||
| 278 | return q|! . '%%' .q!| if $char eq ''; #last % | ||||
| 279 | return q|! . '%%| . $char . q|' . q!| if ! exists $FORMAT_CHARS{$char}; #escape %% | ||||
| 280 | my ($format, $code) = @{$SPRINTF_CHARS{$char}}; | ||||
| 281 | push @$args, $code; | ||||
| 282 | return $format; | ||||
| 283 | 1 | 2µs | }; | ||
| 284 | |||||
| 285 | # spent 18µs within POSIX::strftime::Compiler::__ANON__[/usr/local/share/perl/5.18.2/POSIX/strftime/Compiler.pm:293] which was called:
# once (18µs+0s) by POSIX::strftime::Compiler::compile at line 329 | ||||
| 286 | 1 | 1µs | my ($char,$need9char_ref) = @_; | ||
| 287 | 1 | 1µs | return q|! . '%%' .q!| if $char eq ''; #last % | ||
| 288 | 1 | 900ns | return q|! . '%%| . $char . q|' . q!| if ! exists $FORMAT_CHARS{$char}; #escape %% | ||
| 289 | 1 | 3µs | return q|! . '%| . $char . q|' . q!| if ! exists $LOCALE_CHARS{$char}; #stay | ||
| 290 | 1 | 3µs | my ($code,$flag) = @{$LOCALE_CHARS{$char}}; | ||
| 291 | 1 | 1µs | $$need9char_ref++ if $flag; | ||
| 292 | 1 | 11µs | q|! . | . $code . q| . q!|; | ||
| 293 | 1 | 1µs | }; | ||
| 294 | |||||
| 295 | # spent 580µs (539+41) within POSIX::strftime::Compiler::compile which was called:
# once (539µs+41µs) by POSIX::strftime::Compiler::strftime at line 359 | ||||
| 296 | 1 | 2µs | my ($fmt) = @_; | ||
| 297 | |||||
| 298 | 1 | 6µs | my @weekday_name = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday); | ||
| 299 | 1 | 4µs | my @weekday_abbr = qw(Sun Mon Tue Wed Thu Fri Sat); | ||
| 300 | 1 | 7µs | my @month_name = qw(January February March April May June July August September October November December); | ||
| 301 | 1 | 11µs | my @month_abbr = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); | ||
| 302 | |||||
| 303 | 1 | 15µs | 1 | 2µs | $fmt =~ s/!/\\!/g; # spent 2µs making 1 call to POSIX::strftime::Compiler::CORE:subst |
| 304 | 1 | 4µs | 1 | 700ns | $fmt =~ s!\%E([cCxXyY])!%$1!g; # spent 700ns making 1 call to POSIX::strftime::Compiler::CORE:subst |
| 305 | 1 | 6µs | 1 | 2µs | $fmt =~ s!\%O([deHImMSuUVwWy])!%$1!g; # spent 2µs making 1 call to POSIX::strftime::Compiler::CORE:subst |
| 306 | |||||
| 307 | 1 | 1µs | my $sprintf_fmt = $fmt; | ||
| 308 | 1 | 1µs | my $disable_sprintf=0; | ||
| 309 | 1 | 2µs | my $sprintf_code = ''; | ||
| 310 | 1 | 16µs | 1 | 9µs | while ( $sprintf_fmt =~ m~ (?:\%([\%\+a-zA-Z])) ~gx ) { # spent 9µs making 1 call to POSIX::strftime::Compiler::CORE:match |
| 311 | 1 | 14µs | 1 | 200ns | if ( exists $FORMAT_CHARS{$1} && ! exists $SPRINTF_CHARS{$1} ) { # spent 200ns making 1 call to POSIX::strftime::Compiler::CORE:match |
| 312 | $disable_sprintf++ | ||||
| 313 | } | ||||
| 314 | } | ||||
| 315 | 1 | 100ns | if ( !$disable_sprintf ) { | ||
| 316 | my @args; | ||||
| 317 | $sprintf_fmt =~ s! | ||||
| 318 | (?: | ||||
| 319 | \%([\%\+a-zA-Z]|$) | ||||
| 320 | ) | ||||
| 321 | ! $sprintf_char_handler->($1,\@args) !egx; | ||||
| 322 | $sprintf_code = q~if ( @_ == 9 ) { | ||||
| 323 | return sprintf(q!~ . $sprintf_fmt . q~!,~ . join(",", @args) . q~); | ||||
| 324 | }~; | ||||
| 325 | } | ||||
| 326 | |||||
| 327 | 1 | 2µs | my $posix_fmt = $fmt; | ||
| 328 | 1 | 2µs | my $need9char=0; | ||
| 329 | 2 | 37µs | 4 | 26µs | $posix_fmt =~ s! # spent 18µs making 1 call to POSIX::strftime::Compiler::__ANON__[POSIX/strftime/Compiler.pm:293]
# spent 4µs making 1 call to POSIX::strftime::Compiler::CORE:subst
# spent 4µs making 2 calls to POSIX::strftime::Compiler::CORE:substcont, avg 2µs/call |
| 330 | (?: | ||||
| 331 | \%([\%\+a-zA-Z]|$) | ||||
| 332 | ) | ||||
| 333 | ! $char_handler->($1,\$need9char) !egx; | ||||
| 334 | |||||
| 335 | 1 | 700ns | my $need9char_code=''; | ||
| 336 | 1 | 2µs | if ( $need9char ) { | ||
| 337 | $need9char_code = q~if ( @_ == 6 ) { | ||||
| 338 | my $sec = $_[0]; | ||||
| 339 | @_ = gmtime Time::Local::timegm(@_); | ||||
| 340 | $_[0] = $sec; | ||||
| 341 | }~; | ||||
| 342 | } | ||||
| 343 | 1 | 4µs | my $code = q~sub { | ||
| 344 | if ( @_ != 9 && @_ != 6 ) { | ||||
| 345 | Carp::croak 'Usage: strftime(sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)'; | ||||
| 346 | } | ||||
| 347 | ~ . $sprintf_code . q~ | ||||
| 348 | ~ . $need9char_code . q~ | ||||
| 349 | POSIX::strftime(q!~ . $posix_fmt . q~!,@_); | ||||
| 350 | }~; | ||||
| 351 | 1 | 400µs | my $sub = eval $code; ## no critic # spent 102µs executing statements in string eval # includes 15µs spent executing 1 call to 1 sub defined therein. | ||
| 352 | 1 | 900ns | die $@ ."\n=====\n".$code."\n=====\n" if $@; | ||
| 353 | 1 | 19µs | wantarray ? ($sub,$code) : $sub; | ||
| 354 | } | ||||
| 355 | |||||
| 356 | 1 | 200ns | my %STRFTIME; | ||
| 357 | # spent 700µs (28+671) within POSIX::strftime::Compiler::strftime which was called:
# once (28µs+671µs) by Apache::LogFormat::Compiler::__ANON__[(eval 593)[/usr/local/share/perl/5.18.2/Apache/LogFormat/Compiler.pm:151]:21] at line 5 of (eval 593)[Apache/LogFormat/Compiler.pm:151] | ||||
| 358 | 1 | 1µs | my $fmt = shift; | ||
| 359 | 1 | 19µs | 2 | 671µs | ($STRFTIME{$fmt} ||= compile($fmt))->(@_); # spent 580µs making 1 call to POSIX::strftime::Compiler::compile
# spent 92µs making 1 call to POSIX::strftime::Compiler::__ANON__[(eval 601)[POSIX/strftime/Compiler.pm:351]:12] |
| 360 | } | ||||
| 361 | |||||
| 362 | sub new { | ||||
| 363 | my $class = shift; | ||||
| 364 | my $fmt = shift; | ||||
| 365 | my ($sub,$code) = compile($fmt); | ||||
| 366 | bless [$sub,$code], $class; | ||||
| 367 | } | ||||
| 368 | |||||
| 369 | sub to_string { | ||||
| 370 | my $self = shift; | ||||
| 371 | $self->[0]->(@_); | ||||
| 372 | } | ||||
| 373 | |||||
| 374 | sub code_ref { | ||||
| 375 | my $self = shift; | ||||
| 376 | $self->[0]; | ||||
| 377 | } | ||||
| 378 | |||||
| 379 | 1 | 35µs | 1; | ||
| 380 | __END__ | ||||
# spent 11µs within POSIX::strftime::Compiler::CORE:match which was called 4 times, avg 3µs/call:
# 2 times (1µs+0s) by Apache::LogFormat::Compiler::BEGIN@7 at line 253, avg 700ns/call
# once (9µs+0s) by POSIX::strftime::Compiler::compile at line 310
# once (200ns+0s) by POSIX::strftime::Compiler::compile at line 311 | |||||
# spent 9µs within POSIX::strftime::Compiler::CORE:subst which was called 4 times, avg 2µs/call:
# once (4µs+0s) by POSIX::strftime::Compiler::compile at line 329
# once (2µs+0s) by POSIX::strftime::Compiler::compile at line 305
# once (2µs+0s) by POSIX::strftime::Compiler::compile at line 303
# once (700ns+0s) by POSIX::strftime::Compiler::compile at line 304 | |||||
# spent 4µs within POSIX::strftime::Compiler::CORE:substcont which was called 2 times, avg 2µs/call:
# 2 times (4µs+0s) by POSIX::strftime::Compiler::compile at line 329, avg 2µs/call |