5 use Benchmark qw( cmpthese timethese );
9 my $wanttime = $ARGV[1] || 5;
11 use JSON qw( -support_by_pp -no_export ); # for JSON::PP::Boolean inheritance
16 my $pp = JSON::PP->new->utf8;
17 my $xs = JSON::XS->new->utf8;
22 my $perl = JSON::XS::decode_json $json;
26 printf( "JSON::PP %s\n", JSON::PP->VERSION );
27 printf( "JSON::XS %s\n", JSON::XS->VERSION );
30 print "-----------------------------------\n";
32 print "-----------------------------------\n";
34 $result = timethese( -$wanttime,
36 'JSON::PP' => sub { $pp->encode( $perl ) },
37 'JSON::XS' => sub { $xs->encode( $perl ) },
43 print "-----------------------------------\n";
44 print "->pretty->canonical->encode()\n";
45 print "-----------------------------------\n";
47 $pp->pretty->canonical;
48 $xs->pretty->canonical;
50 $result = timethese( -$wanttime,
52 'JSON::PP' => sub { $pp->encode( $perl ) },
53 'JSON::XS' => sub { $xs->encode( $perl ) },
59 print "-----------------------------------\n";
68 bench_encode.pl json-file
70 bench_encode.pl json-file minimum-time
74 L<JSON::PP> and L<JSON::XS> encoding benchmark.
82 This library is free software; you can redistribute it and/or modify it
83 under the same terms as Perl itself.