… | |
… | |
2 | |
2 | |
3 | # Usage: bench json-file |
3 | # Usage: bench json-file |
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" => ['objToJson $perl' , 'jsonToObj $json'], |
7 | "JSON" => ['JSON::objToJson $perl' , 'JSON::jsonToObj $json'], |
|
|
8 | "JSON::PP" => ['$pp->encode ($perl)' , '$pp->decode ($json)'], |
8 | "JSON::DWIW" => ['$dwiw->to_json ($perl)', '$dwiw->from_json ($json)'], |
9 | "JSON::DWIW" => ['$dwiw->to_json ($perl)' , '$dwiw->from_json ($json)'], |
9 | "JSON::PC" => ['$pc->convert ($perl)' , '$pc->parse ($json)'], |
10 | "JSON::PC" => ['$pc->convert ($perl)' , '$pc->parse ($json)'], |
10 | "JSON::Syck" => ['JSON::Syck::Dump $perl', 'JSON::Syck::Load $json'], |
11 | "JSON::Syck" => ['JSON::Syck::Dump $perl' , 'JSON::Syck::Load $json'], |
11 | "JSON::XS" => ['to_json $perl' , 'from_json $json'], |
12 | "JSON::XS" => ['to_json $perl' , 'from_json $json'], |
12 | "JSON::XS/2" => ['$xs2->encode ($perl)' , '$xs2->decode ($json)'], |
13 | "JSON::XS/2" => ['$xs2->encode ($perl)' , '$xs2->decode ($json)'], |
13 | "JSON::XS/3" => ['$xs3->encode ($perl)' , '$xs3->decode ($json)'], |
14 | "JSON::XS/3" => ['$xs3->encode ($perl)' , '$xs3->decode ($json)'], |
14 | "Storable" => ['Storable::nfreeze $perl', 'Storable::thaw $pst'], |
15 | "Storable" => ['Storable::nfreeze $perl' , 'Storable::thaw $pst'], |
15 | ); |
16 | ); |
16 | |
17 | |
17 | use JSON; |
18 | use JSON (); |
18 | use JSON::DWIW; |
19 | use JSON::DWIW; |
19 | use JSON::PC; |
20 | use JSON::PC; |
|
|
21 | use JSON::PP (); |
20 | use JSON::XS qw(to_json from_json); |
22 | use JSON::XS qw(to_json from_json); |
21 | use JSON::Syck; |
23 | use JSON::Syck; |
22 | use Storable (); |
24 | use Storable (); |
23 | |
25 | |
24 | use Time::HiRes; |
26 | use Time::HiRes; |
… | |
… | |
26 | |
28 | |
27 | use utf8; |
29 | use utf8; |
28 | |
30 | |
29 | my $dwiw = new JSON::DWIW; |
31 | my $dwiw = new JSON::DWIW; |
30 | my $pc = new JSON::PC; |
32 | my $pc = new JSON::PC; |
|
|
33 | my $pp = JSON::PP->new->max_depth (512); |
31 | my $xs2 = JSON::XS->new->utf8->pretty->canonical; |
34 | my $xs2 = JSON::XS->new->utf8->pretty->canonical; |
32 | my $xs3 = JSON::XS->new->utf8->shrink; |
35 | my $xs3 = JSON::XS->new->utf8->shrink; |
33 | |
36 | |
34 | my $json; # the test string |
37 | my $json; # the test string |
35 | |
38 | |
… | |
… | |
52 | #} |
55 | #} |
53 | |
56 | |
54 | sub bench($) { |
57 | sub bench($) { |
55 | my ($code) = @_; |
58 | my ($code) = @_; |
56 | |
59 | |
57 | my $perl = jsonToObj $json; |
60 | my $perl = JSON::XS::jsonToObj $json; |
58 | my $pst = Storable::nfreeze $perl; |
61 | my $pst = Storable::nfreeze $perl; |
59 | |
62 | |
60 | my $count = 5; |
63 | my $count = 5; |
61 | my $times = 200; |
64 | my $times = 200; |
62 | |
65 | |