Subscribed unsubscribe Subscribe Subscribe

DateTime:Formatとか

use strict;
use warnings;

use Benchmark qw/:all/;
use DateTime::Format::Strptime;
use DateTime::Format::MySQL;
use Time::Piece;
use Time::Piece::MySQL;

my $strp = DateTime::Format::Strptime->new(
    pattern => "%Y-%m-%d %H:%M:%S"
);

cmpthese(-1, {
    mysql => sub {
        DateTime::Format::MySQL->parse_datetime('2003-01-16 23:12:01');
    },
    strptime => sub {
        my $strp = DateTime::Format::Strptime->new(
            pattern => "%Y-%m-%d %H:%M:%S"
        );
        $strp->parse_datetime("2003-01-16 23:12:01");
    },
    strptime_use_instance => sub {
        $strp->parse_datetime("2003-01-16 23:12:01");
    },
    time_piece => sub {
        Time::Piece->strptime("2003-01-16 23:12:01", "%Y-%m-%d %H:%M:%S");
    },
    time_piece_mysql => sub {
        Time::Piece->from_mysql_datetime("2003-01-16 23:12:01");
    }
});

Rate strptime strptime_use_instance mysql time_piece_mysql time_piece
strptime 1999/s -- -42% -66% -98% -99%
strptime_use_instance 3446/s 72% -- -42% -97% -98%
mysql 5946/s 197% 73% -- -95% -96%
time_piece_mysql 121662/s 5986% 3430% 1946% -- -22%
time_piece 156392/s 7723% 4438% 2530% 29% --