#!perl

our $DATE = '2015-06-29'; # DATE
our $VERSION = '0.01'; # VERSION

use 5.010001;
use strict;
use warnings;

use App::BenchSerializers;
use Benchmark::Dumb qw(cmpthese);
use Module::Load;

my $contestants = \%App::BenchSerializers::contestants;
my $data = \%App::BenchSerializers::data;

my @mods = grep {$contestants->{$_}{serialize}} sort keys %$contestants;

# load the modules
for my $mod (@mods) { load $mod }

# benchmark
for my $k (sort keys %$data) {
    my $v = $data->{$k};
    next unless ref($v->{data});
    say "Serializing $k ($v->{summary}):";
    my %codes;
    for my $mod (@mods) {
        $codes{$mod} = sub { $contestants->{$mod}{serialize}->($v->{data}) };
    }
    cmpthese(0, \%codes);
    say "";
}

# ABSTRACT: Benchmark Perl data serialization modules
# PODNAME: bench-serializers

__END__

=pod

=encoding UTF-8

=head1 NAME

bench-serializers - Benchmark Perl data serialization modules

=head1 VERSION

This document describes version 0.01 of bench-serializers (from Perl distribution App-BenchSerializers), released on 2015-06-29.

=head1 SYNOPSIS

 % bench-serializers

Sample output:

 Serializing array_int10 (A 10-element array containing ints):
                                 Rate    YAML::Old     JSON::PP   YAML::Syck    YAML::XS      Storable       Sereal JSON::MaybeXS JSON::XS Data::MessagePack
 YAML::Old              4767.5+-9.7/s           --       -94.4%       -96.2%      -97.4%        -98.8%       -99.7%        -99.8%   -99.8%            -99.8%
 JSON::PP                84549.1+-0/s 1673.5+-3.6%           --       -33.1%      -54.6%        -79.3%       -95.5%        -96.6%   -96.6%            -96.7%
 YAML::Syck             126310+-160/s 2549.4+-6.3% 49.39+-0.18%           --      -32.1%        -69.1%       -93.3%        -94.9%   -95.0%            -95.1%
 YAML::XS                186045+-55/s   3802.4+-8%       120.0% 47.29+-0.19%          --        -54.4%       -90.2%        -92.4%   -92.6%            -92.8%
 Storable                 408241+-0/s    8463+-17%       382.8%  223.2+-0.4%      119.4%            --       -78.4%        -83.4%   -83.7%            -84.3%
 Sereal            1.8927e+06+-3000/s  39600+-100% 2138.6+-3.5%   1398.5+-3% 917.3+-1.6% 363.63+-0.73%           --        -23.0%   -24.5%            -27.1%
 JSON::MaybeXS       2.45865e+06+-0/s  51470+-100%      2808.0% 1846.5+-2.4%     1221.5%        502.3%   29.9+-0.2%            --    -1.9%             -5.3%
 JSON::XS            2.50577e+06+-0/s  52460+-110%      2863.7% 1883.8+-2.4%     1246.9%        513.8% 32.39+-0.21%          1.9%       --             -3.5%
 Data::MessagePack 2.5959e+06+-1300/s  54350+-110%      2970.3% 1955.2+-2.7%     1295.3%        535.9% 37.15+-0.23%          5.6%     3.6%                --

=head1 SEE ALSO

=head1 HOMEPAGE

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

=head1 SOURCE

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

=head1 BUGS

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

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
