| Filename | /usr/lib/perl/5.18/Time/Seconds.pm |
| Statements | Executed 36 statements in 2.13ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 36µs | 182µs | Time::Seconds::BEGIN@40 |
| 1 | 1 | 1 | 26µs | 79µs | Time::Seconds::BEGIN@24 |
| 1 | 1 | 1 | 25µs | 164µs | Time::Seconds::BEGIN@23 |
| 1 | 1 | 1 | 23µs | 48µs | Time::Seconds::BEGIN@2 |
| 1 | 1 | 1 | 21µs | 155µs | Time::Seconds::BEGIN@3 |
| 1 | 1 | 1 | 19µs | 82µs | Time::Seconds::BEGIN@26 |
| 1 | 1 | 1 | 15µs | 81µs | Time::Seconds::BEGIN@25 |
| 1 | 1 | 1 | 14µs | 117µs | Time::Seconds::BEGIN@36 |
| 1 | 1 | 1 | 13µs | 43µs | Time::Seconds::BEGIN@32 |
| 1 | 1 | 1 | 13µs | 49µs | Time::Seconds::BEGIN@29 |
| 1 | 1 | 1 | 12µs | 48µs | Time::Seconds::BEGIN@31 |
| 1 | 1 | 1 | 12µs | 51µs | Time::Seconds::BEGIN@28 |
| 1 | 1 | 1 | 11µs | 51µs | Time::Seconds::BEGIN@37 |
| 1 | 1 | 1 | 10µs | 45µs | Time::Seconds::BEGIN@33 |
| 1 | 1 | 1 | 9µs | 44µs | Time::Seconds::BEGIN@30 |
| 1 | 1 | 1 | 9µs | 52µs | Time::Seconds::BEGIN@27 |
| 0 | 0 | 0 | 0s | 0s | Time::Seconds::_get_ovlvals |
| 0 | 0 | 0 | 0s | 0s | Time::Seconds::add |
| 0 | 0 | 0 | 0s | 0s | Time::Seconds::add_to |
| 0 | 0 | 0 | 0s | 0s | Time::Seconds::compare |
| 0 | 0 | 0 | 0s | 0s | Time::Seconds::copy |
| 0 | 0 | 0 | 0s | 0s | Time::Seconds::days |
| 0 | 0 | 0 | 0s | 0s | Time::Seconds::financial_months |
| 0 | 0 | 0 | 0s | 0s | Time::Seconds::hours |
| 0 | 0 | 0 | 0s | 0s | Time::Seconds::minutes |
| 0 | 0 | 0 | 0s | 0s | Time::Seconds::months |
| 0 | 0 | 0 | 0s | 0s | Time::Seconds::new |
| 0 | 0 | 0 | 0s | 0s | Time::Seconds::pretty |
| 0 | 0 | 0 | 0s | 0s | Time::Seconds::seconds |
| 0 | 0 | 0 | 0s | 0s | Time::Seconds::subtract |
| 0 | 0 | 0 | 0s | 0s | Time::Seconds::subtract_from |
| 0 | 0 | 0 | 0s | 0s | Time::Seconds::weeks |
| 0 | 0 | 0 | 0s | 0s | Time::Seconds::years |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Time::Seconds; | ||||
| 2 | 2 | 45µs | 2 | 73µs | # spent 48µs (23+25) within Time::Seconds::BEGIN@2 which was called:
# once (23µs+25µs) by Time::Piece::BEGIN@7 at line 2 # spent 48µs making 1 call to Time::Seconds::BEGIN@2
# spent 25µs making 1 call to strict::import |
| 3 | 2 | 118µs | 2 | 289µs | # spent 155µs (21+134) within Time::Seconds::BEGIN@3 which was called:
# once (21µs+134µs) by Time::Piece::BEGIN@7 at line 3 # spent 155µs making 1 call to Time::Seconds::BEGIN@3
# spent 134µs making 1 call to vars::import |
| 4 | |||||
| 5 | 1 | 39µs | @ISA = 'Exporter'; | ||
| 6 | |||||
| 7 | 1 | 6µs | @EXPORT = qw( | ||
| 8 | ONE_MINUTE | ||||
| 9 | ONE_HOUR | ||||
| 10 | ONE_DAY | ||||
| 11 | ONE_WEEK | ||||
| 12 | ONE_MONTH | ||||
| 13 | ONE_REAL_MONTH | ||||
| 14 | ONE_YEAR | ||||
| 15 | ONE_REAL_YEAR | ||||
| 16 | ONE_FINANCIAL_MONTH | ||||
| 17 | LEAP_YEAR | ||||
| 18 | NON_LEAP_YEAR | ||||
| 19 | ); | ||||
| 20 | |||||
| 21 | 1 | 2µs | @EXPORT_OK = qw(cs_sec cs_mon); | ||
| 22 | |||||
| 23 | 2 | 114µs | 2 | 303µs | # spent 164µs (25+139) within Time::Seconds::BEGIN@23 which was called:
# once (25µs+139µs) by Time::Piece::BEGIN@7 at line 23 # spent 164µs making 1 call to Time::Seconds::BEGIN@23
# spent 139µs making 1 call to constant::import |
| 24 | 2 | 47µs | 2 | 131µs | # spent 79µs (26+52) within Time::Seconds::BEGIN@24 which was called:
# once (26µs+52µs) by Time::Piece::BEGIN@7 at line 24 # spent 79µs making 1 call to Time::Seconds::BEGIN@24
# spent 52µs making 1 call to constant::import |
| 25 | 2 | 69µs | 2 | 147µs | # spent 81µs (15+66) within Time::Seconds::BEGIN@25 which was called:
# once (15µs+66µs) by Time::Piece::BEGIN@7 at line 25 # spent 81µs making 1 call to Time::Seconds::BEGIN@25
# spent 66µs making 1 call to constant::import |
| 26 | 2 | 56µs | 2 | 145µs | # spent 82µs (19+63) within Time::Seconds::BEGIN@26 which was called:
# once (19µs+63µs) by Time::Piece::BEGIN@7 at line 26 # spent 82µs making 1 call to Time::Seconds::BEGIN@26
# spent 63µs making 1 call to constant::import |
| 27 | 2 | 48µs | 2 | 94µs | # spent 52µs (9+43) within Time::Seconds::BEGIN@27 which was called:
# once (9µs+43µs) by Time::Piece::BEGIN@7 at line 27 # spent 52µs making 1 call to Time::Seconds::BEGIN@27
# spent 43µs making 1 call to constant::import |
| 28 | 2 | 37µs | 2 | 91µs | # spent 51µs (12+40) within Time::Seconds::BEGIN@28 which was called:
# once (12µs+40µs) by Time::Piece::BEGIN@7 at line 28 # spent 51µs making 1 call to Time::Seconds::BEGIN@28
# spent 40µs making 1 call to constant::import |
| 29 | 2 | 58µs | 2 | 85µs | # spent 49µs (13+36) within Time::Seconds::BEGIN@29 which was called:
# once (13µs+36µs) by Time::Piece::BEGIN@7 at line 29 # spent 49µs making 1 call to Time::Seconds::BEGIN@29
# spent 36µs making 1 call to constant::import |
| 30 | 2 | 40µs | 2 | 79µs | # spent 44µs (9+35) within Time::Seconds::BEGIN@30 which was called:
# once (9µs+35µs) by Time::Piece::BEGIN@7 at line 30 # spent 44µs making 1 call to Time::Seconds::BEGIN@30
# spent 35µs making 1 call to constant::import |
| 31 | 2 | 37µs | 2 | 85µs | # spent 48µs (12+36) within Time::Seconds::BEGIN@31 which was called:
# once (12µs+36µs) by Time::Piece::BEGIN@7 at line 31 # spent 48µs making 1 call to Time::Seconds::BEGIN@31
# spent 36µs making 1 call to constant::import |
| 32 | 2 | 39µs | 2 | 73µs | # spent 43µs (13+30) within Time::Seconds::BEGIN@32 which was called:
# once (13µs+30µs) by Time::Piece::BEGIN@7 at line 32 # spent 43µs making 1 call to Time::Seconds::BEGIN@32
# spent 30µs making 1 call to constant::import |
| 33 | 2 | 56µs | 2 | 80µs | # spent 45µs (10+35) within Time::Seconds::BEGIN@33 which was called:
# once (10µs+35µs) by Time::Piece::BEGIN@7 at line 33 # spent 45µs making 1 call to Time::Seconds::BEGIN@33
# spent 35µs making 1 call to constant::import |
| 34 | |||||
| 35 | # hacks to make Time::Piece compile once again | ||||
| 36 | 2 | 46µs | 2 | 221µs | # spent 117µs (14+104) within Time::Seconds::BEGIN@36 which was called:
# once (14µs+104µs) by Time::Piece::BEGIN@7 at line 36 # spent 117µs making 1 call to Time::Seconds::BEGIN@36
# spent 104µs making 1 call to constant::import |
| 37 | 2 | 126µs | 2 | 90µs | # spent 51µs (11+40) within Time::Seconds::BEGIN@37 which was called:
# once (11µs+40µs) by Time::Piece::BEGIN@7 at line 37 # spent 51µs making 1 call to Time::Seconds::BEGIN@37
# spent 40µs making 1 call to constant::import |
| 38 | |||||
| 39 | use overload | ||||
| 40 | 1 | 30µs | 1 | 146µs | # spent 182µs (36+146) within Time::Seconds::BEGIN@40 which was called:
# once (36µs+146µs) by Time::Piece::BEGIN@7 at line 48 # spent 146µs making 1 call to overload::import |
| 41 | '0+' => \&seconds, | ||||
| 42 | '""' => \&seconds, | ||||
| 43 | '<=>' => \&compare, | ||||
| 44 | '+' => \&add, | ||||
| 45 | '-' => \&subtract, | ||||
| 46 | '-=' => \&subtract_from, | ||||
| 47 | '+=' => \&add_to, | ||||
| 48 | 1 | 1.11ms | 1 | 182µs | '=' => \© # spent 182µs making 1 call to Time::Seconds::BEGIN@40 |
| 49 | |||||
| 50 | sub new { | ||||
| 51 | my $class = shift; | ||||
| 52 | my ($val) = @_; | ||||
| 53 | $val = 0 unless defined $val; | ||||
| 54 | bless \$val, $class; | ||||
| 55 | } | ||||
| 56 | |||||
| 57 | sub _get_ovlvals { | ||||
| 58 | my ($lhs, $rhs, $reverse) = @_; | ||||
| 59 | $lhs = $lhs->seconds; | ||||
| 60 | |||||
| 61 | if (UNIVERSAL::isa($rhs, 'Time::Seconds')) { | ||||
| 62 | $rhs = $rhs->seconds; | ||||
| 63 | } | ||||
| 64 | elsif (ref($rhs)) { | ||||
| 65 | die "Can't use non Seconds object in operator overload"; | ||||
| 66 | } | ||||
| 67 | |||||
| 68 | if ($reverse) { | ||||
| 69 | return $rhs, $lhs; | ||||
| 70 | } | ||||
| 71 | |||||
| 72 | return $lhs, $rhs; | ||||
| 73 | } | ||||
| 74 | |||||
| 75 | sub compare { | ||||
| 76 | my ($lhs, $rhs) = _get_ovlvals(@_); | ||||
| 77 | return $lhs <=> $rhs; | ||||
| 78 | } | ||||
| 79 | |||||
| 80 | sub add { | ||||
| 81 | my ($lhs, $rhs) = _get_ovlvals(@_); | ||||
| 82 | return Time::Seconds->new($lhs + $rhs); | ||||
| 83 | } | ||||
| 84 | |||||
| 85 | sub add_to { | ||||
| 86 | my $lhs = shift; | ||||
| 87 | my $rhs = shift; | ||||
| 88 | $rhs = $rhs->seconds if UNIVERSAL::isa($rhs, 'Time::Seconds'); | ||||
| 89 | $$lhs += $rhs; | ||||
| 90 | return $lhs; | ||||
| 91 | } | ||||
| 92 | |||||
| 93 | sub subtract { | ||||
| 94 | my ($lhs, $rhs) = _get_ovlvals(@_); | ||||
| 95 | return Time::Seconds->new($lhs - $rhs); | ||||
| 96 | } | ||||
| 97 | |||||
| 98 | sub subtract_from { | ||||
| 99 | my $lhs = shift; | ||||
| 100 | my $rhs = shift; | ||||
| 101 | $rhs = $rhs->seconds if UNIVERSAL::isa($rhs, 'Time::Seconds'); | ||||
| 102 | $$lhs -= $rhs; | ||||
| 103 | return $lhs; | ||||
| 104 | } | ||||
| 105 | |||||
| 106 | sub copy { | ||||
| 107 | Time::Seconds->new(${$_[0]}); | ||||
| 108 | } | ||||
| 109 | |||||
| 110 | sub seconds { | ||||
| 111 | my $s = shift; | ||||
| 112 | return $$s; | ||||
| 113 | } | ||||
| 114 | |||||
| 115 | sub minutes { | ||||
| 116 | my $s = shift; | ||||
| 117 | return $$s / 60; | ||||
| 118 | } | ||||
| 119 | |||||
| 120 | sub hours { | ||||
| 121 | my $s = shift; | ||||
| 122 | $s->minutes / 60; | ||||
| 123 | } | ||||
| 124 | |||||
| 125 | sub days { | ||||
| 126 | my $s = shift; | ||||
| 127 | $s->hours / 24; | ||||
| 128 | } | ||||
| 129 | |||||
| 130 | sub weeks { | ||||
| 131 | my $s = shift; | ||||
| 132 | $s->days / 7; | ||||
| 133 | } | ||||
| 134 | |||||
| 135 | sub months { | ||||
| 136 | my $s = shift; | ||||
| 137 | $s->days / 30.4368541; | ||||
| 138 | } | ||||
| 139 | |||||
| 140 | sub financial_months { | ||||
| 141 | my $s = shift; | ||||
| 142 | $s->days / 30; | ||||
| 143 | } | ||||
| 144 | |||||
| 145 | sub years { | ||||
| 146 | my $s = shift; | ||||
| 147 | $s->days / 365.24225; | ||||
| 148 | } | ||||
| 149 | |||||
| 150 | sub pretty { | ||||
| 151 | my $s = shift; | ||||
| 152 | my $str = ""; | ||||
| 153 | if ($s < 0) { | ||||
| 154 | $s = -$s; | ||||
| 155 | $str = "minus "; | ||||
| 156 | } | ||||
| 157 | if ($s >= ONE_MINUTE) { | ||||
| 158 | if ($s >= ONE_HOUR) { | ||||
| 159 | if ($s >= ONE_DAY) { | ||||
| 160 | my $days = sprintf("%d", $s->days); # does a "floor" | ||||
| 161 | $str = $days . " days, "; | ||||
| 162 | $s -= ($days * ONE_DAY); | ||||
| 163 | } | ||||
| 164 | my $hours = sprintf("%d", $s->hours); | ||||
| 165 | $str .= $hours . " hours, "; | ||||
| 166 | $s -= ($hours * ONE_HOUR); | ||||
| 167 | } | ||||
| 168 | my $mins = sprintf("%d", $s->minutes); | ||||
| 169 | $str .= $mins . " minutes, "; | ||||
| 170 | $s -= ($mins * ONE_MINUTE); | ||||
| 171 | } | ||||
| 172 | $str .= $s->seconds . " seconds"; | ||||
| 173 | return $str; | ||||
| 174 | } | ||||
| 175 | |||||
| 176 | 1 | 14µs | 1; | ||
| 177 | __END__ |