Skip to content

Instantly share code, notes, and snippets.

@JEEN
Last active August 29, 2015 14:08
Show Gist options
  • Save JEEN/7685b2d8806a5a1ce95d to your computer and use it in GitHub Desktop.
Save JEEN/7685b2d8806a5a1ce95d to your computer and use it in GitHub Desktop.
Time::Moment-Inherited vs DateTime
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