… | |
… | |
5 | use JSON; |
5 | use JSON; |
6 | use JSON::DWIW; |
6 | use JSON::DWIW; |
7 | use JSON::PC; |
7 | use JSON::PC; |
8 | use JSON::XS qw(to_json from_json); |
8 | use JSON::XS qw(to_json from_json); |
9 | use JSON::Syck; |
9 | use JSON::Syck; |
|
|
10 | use Storable (); |
10 | |
11 | |
11 | use Time::HiRes; |
12 | use Time::HiRes; |
12 | use List::Util; |
13 | use List::Util; |
13 | |
14 | |
14 | use utf8; |
15 | use utf8; |
… | |
… | |
20 | |
21 | |
21 | my $json; # the test string |
22 | my $json; # the test string |
22 | |
23 | |
23 | local $/; |
24 | local $/; |
24 | $json = <>; |
25 | $json = <>; |
|
|
26 | |
|
|
27 | # fix syck-brokenised stuff |
|
|
28 | $json = JSON::XS->new->ascii(1)->encode (JSON::Syck::Load $json); |
25 | |
29 | |
26 | #srand 0; $json = JSON::XS->new->utf8(1)->ascii(0)->encode ([join "", map +(chr rand 255), 0..2047]); |
30 | #srand 0; $json = JSON::XS->new->utf8(1)->ascii(0)->encode ([join "", map +(chr rand 255), 0..2047]); |
27 | |
31 | |
28 | #if (1) { |
32 | #if (1) { |
29 | # use Storable; |
33 | # use Storable; |
… | |
… | |
41 | "JSON::PC" => ['$pc->convert ($perl)' , '$pc->parse ($json)'], |
45 | "JSON::PC" => ['$pc->convert ($perl)' , '$pc->parse ($json)'], |
42 | "JSON::Syck" => ['JSON::Syck::Dump $perl', 'JSON::Syck::Load $json'], |
46 | "JSON::Syck" => ['JSON::Syck::Dump $perl', 'JSON::Syck::Load $json'], |
43 | "JSON::XS" => ['to_json $perl' , 'from_json $json'], |
47 | "JSON::XS" => ['to_json $perl' , 'from_json $json'], |
44 | "JSON::XS/2" => ['$xs2->encode ($perl)' , '$xs2->decode ($json)'], |
48 | "JSON::XS/2" => ['$xs2->encode ($perl)' , '$xs2->decode ($json)'], |
45 | "JSON::XS/3" => ['$xs3->encode ($perl)' , '$xs3->decode ($json)'], |
49 | "JSON::XS/3" => ['$xs3->encode ($perl)' , '$xs3->decode ($json)'], |
|
|
50 | "Storable" => ['Storable::nfreeze $perl', 'Storable::thaw $pst'], |
46 | ); |
51 | ); |
47 | |
52 | |
48 | sub bench($) { |
53 | sub bench($) { |
49 | my ($code) = @_; |
54 | my ($code) = @_; |
50 | |
55 | |
51 | my $perl = jsonToObj $json; |
56 | my $perl = jsonToObj $json; |
|
|
57 | my $pst = Storable::nfreeze $perl; |
|
|
58 | |
52 | my $count = 20; |
59 | my $count = 2; |
53 | my $times = 25; |
60 | my $times = 25; |
54 | |
61 | |
55 | my $cent = eval "sub { " . (join ";", ($code) x $count) . "}"; |
62 | my $cent = eval "sub { " . (join ";", ($code) x $count) . "}"; |
56 | $cent->(); |
63 | $cent->(); |
57 | |
64 | |