Created
April 27, 2017 09:01
-
-
Save yowcow/16bf332ae5c0c1b83cd61b123d64c4e2 to your computer and use it in GitHub Desktop.
DateTime vs. POSIX::strftime()
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(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