← Index
NYTProf Performance Profile   « line view »
For /home/ss5/perl5/perlbrew/perls/perl-5.22.0/bin/benchmarkanything-storage
  Run on Mon Jan 29 16:55:34 2018
Reported on Mon Jan 29 16:57:07 2018

Filename/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/Time/Duration/Parse.pm
StatementsExecuted 14 statements in 351µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111343µs396µsTime::Duration::Parse::::BEGIN@8Time::Duration::Parse::BEGIN@8
11111µs11µsTime::Duration::Parse::::BEGIN@3Time::Duration::Parse::BEGIN@3
1115µs6µsTime::Duration::Parse::::BEGIN@4Time::Duration::Parse::BEGIN@4
1114µs24µsTime::Duration::Parse::::BEGIN@7Time::Duration::Parse::BEGIN@7
1114µs8µsTime::Duration::Parse::::BEGIN@5Time::Duration::Parse::BEGIN@5
0000s0sTime::Duration::Parse::::parse_durationTime::Duration::Parse::parse_duration
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Time::Duration::Parse;
21300ns$Time::Duration::Parse::VERSION = '0.13';
3227µs111µs
# spent 11µs within Time::Duration::Parse::BEGIN@3 which was called: # once (11µs+0s) by CHI::Util::BEGIN@10 at line 3
use 5.006;
# spent 11µs making 1 call to Time::Duration::Parse::BEGIN@3
4212µs28µs
# spent 6µs (5+1) within Time::Duration::Parse::BEGIN@4 which was called: # once (5µs+1µs) by CHI::Util::BEGIN@10 at line 4
use strict;
# spent 6µs making 1 call to Time::Duration::Parse::BEGIN@4 # spent 1µs making 1 call to strict::import
5212µs211µs
# spent 8µs (4+3) within Time::Duration::Parse::BEGIN@5 which was called: # once (4µs+3µs) by CHI::Util::BEGIN@10 at line 5
use warnings;
# spent 8µs making 1 call to Time::Duration::Parse::BEGIN@5 # spent 3µs making 1 call to warnings::import
6
7213µs244µs
# spent 24µs (4+20) within Time::Duration::Parse::BEGIN@7 which was called: # once (4µs+20µs) by CHI::Util::BEGIN@10 at line 7
use Carp;
# spent 24µs making 1 call to Time::Duration::Parse::BEGIN@7 # spent 20µs making 1 call to Exporter::import
82266µs2412µs
# spent 396µs (343+53) within Time::Duration::Parse::BEGIN@8 which was called: # once (343µs+53µs) by CHI::Util::BEGIN@10 at line 8
use Exporter::Lite;
# spent 396µs making 1 call to Time::Duration::Parse::BEGIN@8 # spent 16µs making 1 call to Exporter::Lite::import
91500nsour @EXPORT = qw( parse_duration );
10
11# This map is taken from Cache and Cache::Cache
12# map of expiration formats to their respective time in seconds
13115µsmy %Units = ( map(($_, 1), qw(s second seconds sec secs)),
14 map(($_, 60), qw(m minute minutes min mins)),
15 map(($_, 60*60), qw(h hr hour hours)),
16 map(($_, 60*60*24), qw(d day days)),
17 map(($_, 60*60*24*7), qw(w week weeks)),
18 map(($_, 60*60*24*30), qw(M month months mo mon mons)),
19 map(($_, 60*60*24*365), qw(y year years)) );
20
21sub parse_duration {
22 my $timespec = shift;
23
24 # You can have an optional leading '+', which has no effect
25 $timespec =~ s/^\s*\+\s*//;
26
27 # Treat a plain number as a number of seconds (and parse it later)
28 if ($timespec =~ /^\s*(-?\d+(?:[.,]\d+)?)\s*$/) {
29 $timespec = "$1s";
30 }
31
32 # Convert hh:mm(:ss)? to something we understand
33 $timespec =~ s/\b(\d+):(\d\d):(\d\d)\b/$1h $2m $3s/g;
34 $timespec =~ s/\b(\d+):(\d\d)\b/$1h $2m/g;
35
36 my $duration = 0;
37 while ($timespec =~ s/^\s*(-?\d+(?:[.,]\d+)?)\s*([a-zA-Z]+)(?:\s*(?:,|and)\s*)*//i) {
38 my($amount, $unit) = ($1, $2);
39 $unit = lc($unit) unless length($unit) == 1;
40
41 if (my $value = $Units{$unit}) {
42 $amount =~ s/,/./;
43 $duration += $amount * $value;
44 } else {
45 Carp::croak "Unknown timespec: $1 $2";
46 }
47 }
48
49 if ($timespec =~ /\S/) {
50 Carp::croak "Unknown timespec: $timespec";
51 }
52
53 return sprintf "%.0f", $duration;
54}
55
5615µs1;
57__END__