#!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} && $contestants->{$_}{deserialize}
} 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 "Deserializing $k ($v->{summary}):";
    my %codes;
    for my $mod (@mods) {
        my $datum = $contestants->{$mod}{serialize}->($v->{data});
        $codes{$mod} = sub { $contestants->{$mod}{deserialize}->($datum) };
    }
    cmpthese(0, \%codes);
    say "";
}

# ABSTRACT: Benchmark Perl data deserialization modules
# PODNAME: bench-deserializers

__END__

=pod

=encoding UTF-8

=head1 NAME

bench-deserializers - Benchmark Perl data deserialization modules

=head1 VERSION

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

=head1 SYNOPSIS

 % bench-deserializers

Sample output:

 Deserializing array_int10 (A 10-element array containing ints):
 Data::MessagePack: Reached maximum number of iterations. Stopping. Precision not reached.
                                 Rate Data::MessagePack    YAML::Old      JSON::PP    YAML::Syck      YAML::XS      Storable       Sereal JSON::XS JSON::MaybeXS
 Data::MessagePack   -1.5174e+07+-0/s                --   -590142.2%     -40622.9%     -14431.5%     -11144.8%      -2081.8%     -1133.7%  -993.4%       -989.9%
 YAML::Old              2571.7+-2.8/s           -100.0%           --        -93.1%        -97.6%        -98.1%        -99.7%       -99.8%   -99.8%        -99.8%
 JSON::PP                 37445+-75/s           -100.2% 1356.1+-3.3%            --        -64.6%        -72.7%        -95.1%       -97.4%   -97.8%        -97.8%
 YAML::Syck              105879+-37/s           -100.7% 4017.1+-4.6% 182.75+-0.57%            --        -22.9%        -86.2%       -92.8%   -93.8%        -93.8%
 YAML::XS                137385+-52/s           -100.9% 5242.2+-6.1% 266.89+-0.75%         29.8%            --        -82.1%       -90.6%   -91.9%        -91.9%
 Storable               765680+-980/s           -105.0%   29674+-50%  1944.8+-4.8% 623.17+-0.96% 457.33+-0.74%            --       -47.8%   -54.9%        -55.1%
 Sereal            1.4679e+06+-4000/s           -109.7%  56980+-170%     3820+-13%  1286.4+-3.8%     968.5+-3%  91.71+-0.58%           --   -13.6%        -13.9%
 JSON::XS          1.6984e+06+-1700/s           -111.2%   65942+-96%     4436+-10%  1504.1+-1.7%  1136.2+-1.3% 121.81+-0.36%  15.7+-0.34%       --         -0.4%
 JSON::MaybeXS      1.70515e+06+-29/s           -111.2%   66205+-71%  4453.7+-9.1%       1510.5%       1141.1%  122.7+-0.28% 16.16+-0.32%     0.4%            --

=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
