Skip to content

Instantly share code, notes, and snippets.

@ken39arg
Created June 29, 2018 06:01
Show Gist options
  • Select an option

  • Save ken39arg/050a8f777d6edbef43e6c41a5d2cfb3e to your computer and use it in GitHub Desktop.

Select an option

Save ken39arg/050a8f777d6edbef43e6c41a5d2cfb3e to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use Benchmark qw(:all);
use DateTime;
my $now = DateTime->now();
my $last = $now->clone->subtract(minutes => 10);
my $now_epoch = scalar time();
printf "%s\n", $now->strftime('%Y%m%d');
printf "%s\n", $now->ymd('');
cmpthese(
100000, {
"strftime" => sub {
$now->strftime('%Y%m%d');
},
"ymd" => sub {
$now->ymd('');
},
"sprintf" => sub {
sprintf("%04d%02d%02d", $now->year(), $now->month(), $now->day());
},
}
);
__DATA__
Rate strftime sprintf ymd
strftime 208333/s -- -75% -83%
sprintf 833333/s 300% -- -33%
ymd 1250000/s 500% 50% --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment