#!perl

our $DATE = '2015-06-19'; # DATE
our $VERSION = '0.02'; # VERSION

use 5.010001;
use strict;
use warnings;

use Benchmark::Dumb qw(cmpthese);
use DateTime;
use Time::Moment;
use Time::Piece ();

my $dt1 = DateTime    ->new(year=>2015, month=>6, day=>19, hour=>14, minute=>7, second=>59, time_zone=>'UTC');
my $dt2 = DateTime    ->new(year=>2015, month=>7, day=> 1, hour=>14, minute=>7, second=>59, time_zone=>'UTC');
my $tm1 = Time::Moment->from_object($dt1);
my $tm2 = Time::Moment->from_object($dt2);
my $tp1 = Time::Piece::gmtime($dt1->epoch);
my $tp2 = Time::Piece::gmtime($dt2->epoch);

cmpthese(
    0,
    {
        'DateTime     1k_comp2' => sub { DateTime->compare($dt1, $dt2) for 1..1000 },
        'Time::Moment 1k_comp2' => sub { $tm1->compare($tm2)           for 1..1000 },
        'Time::Piece  1k_comp2' => sub { no warnings 'void'; for (1..1000) { $tm1 <=> $tm2 } },
    },
);

# ABSTRACT: Benchmark date modules: compare date objects
# PODNAME: bench-date-modules-compare

__END__

=pod

=encoding UTF-8

=head1 NAME

bench-date-modules-compare - Benchmark date modules: compare date objects

=head1 VERSION

This document describes version 0.02 of bench-date-modules-compare (from Perl distribution App-BenchDateModules), released on 2015-06-19.

=head1 SYNOPSIS

 % bench-date-modules-compare

Sample output:

                                   Rate DateTime     1k_comp2 Time::Piece  1k_comp2 Time::Moment 1k_comp2
 DateTime     1k_comp2   138.13+-0.26/s                    --                -97.6%                -98.5%
 Time::Piece  1k_comp2    5642.9+-5.1/s          3985.3+-8.5%                    --                -38.9%
 Time::Moment 1k_comp2 9240.12+-0.013/s             6590+-13%          63.75+-0.15%                    --

=head1 DESCRIPTION

comp2: Compare 2 date objects with compare() 1000 times.

=head1 SEE ALSO

=head1 HOMEPAGE

Please visit the project's homepage at L<https://metacpan.org/release/App-BenchDateModules>.

=head1 SOURCE

Source repository is at L<https://github.com/perlancar/perl-App-BenchDateModules>.

=head1 BUGS

Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=App-BenchDateModules>

When submitting a bug or request, please include a test-file or a
patch to an existing test-file that illustrates the bug or desired
feature.

=head1 AUTHOR

perlancar <perlancar@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2015 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut
