| OLD | NEW | 
|---|
|  | (Empty) | 
| 1 #!/usr/bin/perl |  | 
| 2 |  | 
| 3 use strict; |  | 
| 4 use warnings; |  | 
| 5 use Benchmark qw( cmpthese timethese ); |  | 
| 6 |  | 
| 7 our $VERSION = '1.00'; |  | 
| 8 |  | 
| 9 my $wanttime = $ARGV[1] || 5; |  | 
| 10 |  | 
| 11 use JSON qw( -support_by_pp -no_export ); # for JSON::PP::Boolean inheritance |  | 
| 12 use JSON::PP (); |  | 
| 13 use JSON::XS (); |  | 
| 14 use utf8; |  | 
| 15 |  | 
| 16 my $pp   = JSON::PP->new->utf8; |  | 
| 17 my $xs   = JSON::XS->new->utf8; |  | 
| 18 |  | 
| 19 local $/; |  | 
| 20 |  | 
| 21 my $json = <>; |  | 
| 22 my $perl = JSON::XS::decode_json $json; |  | 
| 23 my $result; |  | 
| 24 |  | 
| 25 |  | 
| 26 printf( "JSON::PP %s\n", JSON::PP->VERSION ); |  | 
| 27 printf( "JSON::XS %s\n", JSON::XS->VERSION ); |  | 
| 28 |  | 
| 29 |  | 
| 30 print "-----------------------------------\n"; |  | 
| 31 print "->decode()\n"; |  | 
| 32 print "-----------------------------------\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 ); |  | 
| 41 cmpthese( $result ); |  | 
| 42 |  | 
| 43 print "-----------------------------------\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 |  | 
| 58 L<JSON::PP> and L<JSON::XS> decoding benchmark. |  | 
| 59 |  | 
| 60 =head1 AUTHOR |  | 
| 61 |  | 
| 62 makamaka |  | 
| 63 |  | 
| 64 =head1 LISENCE |  | 
| 65 |  | 
| 66 This library is free software; you can redistribute it and/or modify it |  | 
| 67 under the same terms as Perl itself. |  | 
| 68 |  | 
| 69 =cut |  | 
| 70 |  | 
| OLD | NEW | 
|---|