Debian Codegraph @

eg/bench_decode.pl

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