FU

 view release on metacpan or  search on metacpan

bench.PL  view on Meta::CPAN





use FU::Util 'json_format', 'json_parse';

sub defjson($name, $canon, $text, $val) {
    # Use similar options for fair comparisons.
    my $cp = Cpanel::JSON::XS->new->allow_nonref->unblessed_bool->convert_blessed;
    my $pp = JSON::PP->new->allow_nonref->core_bools->convert_blessed;
    my $xs = JSON::XS->new->allow_nonref->boolean_values([false,true])->convert_blessed;
    my $si = JSON::SIMD->new->allow_nonref->core_bools->convert_blessed;
    my $c_cp = Cpanel::JSON::XS->new->allow_nonref->unblessed_bool->convert_blessed->canonical;
    my $c_pp = JSON::PP->new->allow_nonref->core_bools->convert_blessed->canonical;
    my $c_xs = JSON::XS->new->allow_nonref->boolean_values([false,true])->convert_blessed->canonical;
    my $c_si = JSON::SIMD->new->allow_nonref->core_bools->convert_blessed->canonical;
    my $enc = json_format $val;
    def "json/$name", $text, [ 'Encode', $canon ? 'Canonical' : (), 'Decode' ],
        [ 'JSON::PP',         undef, sub { $pp->encode($val) }, $canon ? sub { $c_pp->encode($val) } : (), sub { $pp->decode($enc) } ],
        [ 'JSON::Tiny',       undef, sub { JSON::Tiny::to_json($val) }, $canon ? undef : (), sub { JSON::Tiny::from_json($enc) } ],
        [ 'Cpanel::JSON::XS', undef, sub { $cp->encode($val) }, $canon ? sub { $c_cp->encode($val) } : (), sub { $cp->decode($enc) } ],
        [ 'JSON::SIMD',       undef, sub { $si->encode($val) }, $canon ? sub { $c_si->encode($val) } : (), sub { $si->decode($enc) } ],
        [ 'JSON::XS',         undef, sub { $xs->encode($val) }, $canon ? sub { $c_xs->encode($val) } : (), sub { $xs->decode($enc) } ],
        [ 'FU::Util',         'FU',  sub { json_format $val  }, $canon ? sub { json_format $val, canonical => 1 } : (), sub { json_parse $enc } ];
}



( run in 0.625 second using v1.01-cache-2.11-cpan-9ff20fc0ed8 )