Date-Reformat
view release on metacpan or search on metacpan
examples/benchmark_date_parse.pl view on Meta::CPAN
use Benchmark;
use Date::Parse;
my $strptime = '%Y-%m-%d %H:%M:%S%Z';
my $date_string = '2015-01-14 21:07:31Z';
my $tests = [
{
'label' => 'Parse string',
'iterations' => 100000,
'coderef' => sub {
my $test_output = Date::Parse::str2time($date_string);
},
},
];
foreach my $test (@$tests) {
Benchmark::timethis(
$test->{'iterations'},
$test->{'coderef'},
$test->{'label'},
);
}
examples/benchmark_date_reformat.pl view on Meta::CPAN
'heuristic' => 'ymd',
},
'formatter' => {
'strftime' => $strptime,
},
);
my $tests = [
{
'label' => 'Initialize',
'iterations' => 10000,
'coderef' => sub {
my $test_parser = Date::Reformat->new(
'parser' => {
'strptime' => $strptime,
},
);
},
},
{
'label' => 'Parse strptime',
'iterations' => 100000,
'coderef' => sub {
my $test_output = $strptime_parser->parse_date($date_string);
},
},
{
'label' => 'Parse heuristic',
'iterations' => 100000,
'coderef' => sub {
my $test_output = $heuristic_parser->parse_date($date_string);
},
},
{
'label' => 'Reformat strptime',
'iterations' => 100000,
'coderef' => sub {
my $test_output = $strptime_parser->reformat_date($date_string);
},
},
{
'label' => 'Reformat heuristic',
'iterations' => 100000,
'coderef' => sub {
my $test_output = $heuristic_parser->reformat_date($date_string);
},
},
];
foreach my $test (@$tests) {
Benchmark::timethis(
$test->{'iterations'},
$test->{'coderef'},
$test->{'label'},
);
}
examples/benchmark_datetime.pl view on Meta::CPAN
my $strptime = '%Y-%m-%d %H:%M:%S%Z';
my $date_string = '2015-01-14 21:07:31Z';
my $strptime_parser = DateTime::Format::Strptime->new(
'pattern' => $strptime,
);
my $tests = [
{
'label' => 'Initialize',
'iterations' => 10000,
'coderef' => sub {
my $test_parser = DateTime::Format::Strptime->new(
'pattern' => $strptime,
);
},
},
{
'label' => 'Parse strptime',
'iterations' => 10000,
'coderef' => sub {
my $test_output = $strptime_parser->parse_datetime($date_string);
},
},
];
foreach my $test (@$tests) {
Benchmark::timethis(
$test->{'iterations'},
$test->{'coderef'},
$test->{'label'},
);
}
examples/benchmark_reformat_datetime.pl view on Meta::CPAN
'time_zone' => $time_zone,
);
},
'params' => [qw(year month day hour minute second time_zone)],
},
);
my $tests = [
{
'label' => 'Reformat to DateTime',
'iterations' => 10000,
'coderef' => sub {
my $test_output = $strptime2datetime->reformat_date($date_string);
},
},
];
foreach my $test (@$tests) {
Benchmark::timethis(
$test->{'iterations'},
$test->{'coderef'},
$test->{'label'},
);
}
examples/benchmark_reformat_time_moment.pl view on Meta::CPAN
'offset' => 0,
);
},
'params' => [qw(year month day hour minute second time_zone)],
},
);
my $tests = [
{
'label' => 'Reformat to Time::Moment',
'iterations' => 100000,
'coderef' => sub {
my $test_output = $strptime2time_moment->reformat_date($date_string);
},
},
];
foreach my $test (@$tests) {
Benchmark::timethis(
$test->{'iterations'},
$test->{'coderef'},
$test->{'label'},
);
}
examples/benchmark_time_moment.pl view on Meta::CPAN
use Benchmark;
use Time::Moment;
my $strptime = '%Y-%m-%d %H:%M:%S%Z';
my $date_string = '2015-01-14 21:07:31Z';
my $tests = [
{
'label' => 'Parse string',
'iterations' => 1000000,
'coderef' => sub {
my $test_output = Time::Moment->from_string($date_string, 'lenient' => 1);
},
},
];
foreach my $test (@$tests) {
Benchmark::timethis(
$test->{'iterations'},
$test->{'coderef'},
$test->{'label'},
);
}
( run in 2.061 seconds using v1.01-cache-2.11-cpan-71847e10f99 )