Skip to content

Instantly share code, notes, and snippets.

@yowcow
Created April 27, 2017 09:01
Show Gist options
  • Select an option

  • Save yowcow/16bf332ae5c0c1b83cd61b123d64c4e2 to your computer and use it in GitHub Desktop.

Select an option

Save yowcow/16bf332ae5c0c1b83cd61b123d64c4e2 to your computer and use it in GitHub Desktop.
DateTime vs. POSIX::strftime()
use strict;
use warnings;
use Benchmark qw(cmpthese);
use DateTime;
use POSIX;
cmpthese(
200_000 => {
'DateTime' => sub {
DateTime->from_epoch(
epoch => time(),
time_zone => 'Asia/Tokyo'
)->strftime('%FT%T');
},
'POSIX::strftime' => sub {
POSIX::strftime('%FT%T', localtime);
},
}
);
=pod
Rate DateTime POSIX::strftime
DateTime 8807/s -- -96%
POSIX::strftime 250000/s 2739% --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment