Last active
August 29, 2015 14:08
-
-
Save JEEN/7685b2d8806a5a1ce95d to your computer and use it in GitHub Desktop.
Time::Moment-Inherited vs DateTime
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
package Time::Moment::Lite; | |
use parent 'Time::Moment'; | |
sub last_day_of_month { | |
shift->with_day_of_month(1)->minus_days(1); | |
} | |
sub as_str { | |
shift->strftime('%Y-%m-%d %H:%M:%S'); | |
} | |
package main; | |
use Benchmark qw(:all) ; | |
use DateTime; | |
my $dt = DateTime->now( time_zone => 'Asia/Seoul' ); | |
timethese(10000, { | |
'DateTime' => sub { DateTime->last_day_of_month( year => $dt->year, month => $dt->month )->strftime('%Y-%m-%d %H:%M:%S') }, | |
'Time::Moment' => sub { Time::Moment::Lite->now->last_day_of_month->as_str }, | |
}); | |
__END__ | |
Benchmark: timing 10000 iterations of Name1, Name2... | |
Name1: 1 wallclock secs ( 0.95 usr + 0.00 sys = 0.95 CPU) @ 10526.32/s (n=10000) | |
Name2: 0 wallclock secs ( 0.03 usr + 0.00 sys = 0.03 CPU) @ 333333.33/s (n=10000) | |
(warning: too few iterations for a reliable count) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment