… | |
… | |
4 | |
4 | |
5 | # which modules to test (JSON usually excluded because its so slow) |
5 | # which modules to test (JSON usually excluded because its so slow) |
6 | my %tst = ( |
6 | my %tst = ( |
7 | # "JSON" => ['JSON::objToJson $perl' , 'JSON::jsonToObj $json'], |
7 | # "JSON" => ['JSON::objToJson $perl' , 'JSON::jsonToObj $json'], |
8 | # "JSON::PP" => ['$pp->encode ($perl)' , '$pp->decode ($json)'], |
8 | # "JSON::PP" => ['$pp->encode ($perl)' , '$pp->decode ($json)'], |
9 | # "JSON::DWIW" => ['$dwiw->to_json ($perl)' , '$dwiw->from_json ($json)'], |
9 | "JSON::DWIW" => ['$dwiw->to_json ($perl)' , '$dwiw->from_json ($json)'], |
10 | # "JSON::PC" => ['$pc->convert ($perl)' , '$pc->parse ($json)'], |
10 | # "JSON::PC" => ['$pc->convert ($perl)' , '$pc->parse ($json)'], |
11 | # "JSON::Syck" => ['JSON::Syck::Dump $perl' , 'JSON::Syck::Load $json'], |
11 | "JSON::Syck" => ['JSON::Syck::Dump $perl' , 'JSON::Syck::Load $json'], |
12 | "JSON::XS" => ['to_json $perl' , 'from_json $json'], |
12 | "JSON::XS" => ['encode_json $perl' , 'decode_json $json'], |
13 | "JSON::XS/2" => ['$xs2->encode ($perl)' , '$xs2->decode ($json)'], |
13 | "JSON::XS/2" => ['$xs2->encode ($perl)' , '$xs2->decode ($json)'], |
14 | "JSON::XS/3" => ['$xs3->encode ($perl)' , '$xs3->decode ($json)'], |
14 | "JSON::XS/3" => ['$xs3->encode ($perl)' , '$xs3->decode ($json)'], |
15 | "Storable" => ['Storable::nfreeze $perl' , 'Storable::thaw $pst'], |
15 | "Storable" => ['Storable::nfreeze $perl' , 'Storable::thaw $pst'], |
16 | ); |
16 | ); |
17 | |
17 | |
18 | use JSON (); |
18 | use JSON (); |
19 | use JSON::DWIW; |
19 | use JSON::DWIW; |
20 | use JSON::PC; |
20 | use JSON::PC; |
21 | use JSON::PP (); |
21 | use JSON::PP (); |
22 | use JSON::XS qw(to_json from_json); |
22 | use JSON::XS qw(encode_json decode_json); |
23 | use JSON::Syck; |
23 | use JSON::Syck; |
24 | use Storable (); |
24 | use Storable (); |
25 | |
25 | |
26 | use Time::HiRes; |
26 | use Time::HiRes; |
27 | use List::Util; |
27 | use List::Util; |
… | |
… | |
38 | |
38 | |
39 | local $/; |
39 | local $/; |
40 | $json = <>; |
40 | $json = <>; |
41 | |
41 | |
42 | # fix syck-brokenised stuff |
42 | # fix syck-brokenised stuff |
43 | $json = JSON::XS->new->ascii(1)->encode (JSON::Syck::Load $json); |
43 | #$json = JSON::XS->new->ascii(1)->encode (JSON::Syck::Load $json); |
44 | |
44 | |
45 | #srand 0; $json = JSON::XS->new->utf8(1)->ascii(0)->encode ([join "", map +(chr rand 255), 0..2047]); |
45 | #srand 0; $json = JSON::XS->new->utf8(1)->ascii(0)->encode ([join "", map +(chr rand 255), 0..2047]); |
46 | |
46 | |
47 | #if (1) { |
47 | #if (1) { |
48 | # use Storable; |
48 | # use Storable; |
… | |
… | |
55 | #} |
55 | #} |
56 | |
56 | |
57 | sub bench($) { |
57 | sub bench($) { |
58 | my ($code) = @_; |
58 | my ($code) = @_; |
59 | |
59 | |
60 | my $perl = JSON::XS::from_json $json; |
60 | my $perl = JSON::XS::decode_json $json; |
61 | my $pst = Storable::nfreeze $perl; |
61 | my $pst = Storable::nfreeze $perl; |
62 | |
62 | |
63 | my $count = 5; |
63 | my $count = 5; |
64 | my $times = 200; |
64 | my $times = 200; |
65 | |
65 | |