1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use Benchmark qw( cmpthese timethese );
6
7our $VERSION = '1.00';
8
9my $wanttime = $ARGV[1] || 5;
10
11use JSON qw( -support_by_pp -no_export ); # for JSON::PP::Boolean inheritance
12use JSON::PP ();
13use JSON::XS ();
14use utf8;
15
16my $pp   = JSON::PP->new->utf8;
17my $xs   = JSON::XS->new->utf8;
18
19local $/;
20
21my $json = <>;
22my $perl = JSON::XS::decode_json $json;
23my $result;
24
25
26printf( "JSON::PP %s\n", JSON::PP->VERSION );
27printf( "JSON::XS %s\n", JSON::XS->VERSION );
28
29
30print "-----------------------------------\n";
31print "->decode()\n";
32print "-----------------------------------\n";
33
34$result = timethese( -$wanttime,
35    {
36        'JSON::PP' => sub { $pp->decode( $json ) },
37        'JSON::XS' => sub { $xs->decode( $json ) },
38    },
39    'none'
40);
41cmpthese( $result );
42
43print "-----------------------------------\n";
44
45
46__END__
47
48=pod
49
50=head1 SYNOPSYS
51
52  bench_decode.pl json-file
53  # or
54  bench_decode.pl json-file minimum-time
55
56=head1 DESCRIPTION
57
58L<JSON::PP> and L<JSON::XS> decoding benchmark.
59
60=head1 AUTHOR
61
62makamaka
63
64=head1 LISENCE
65
66This library is free software; you can redistribute it and/or modify it
67under the same terms as Perl itself.
68
69=cut
70
71