Created
June 29, 2018 06:01
-
-
Save ken39arg/050a8f777d6edbef43e6c41a5d2cfb3e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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