… | |
… | |
13 | |
13 | |
14 | use utf8; |
14 | use utf8; |
15 | |
15 | |
16 | my $dwiw = new JSON::DWIW; |
16 | my $dwiw = new JSON::DWIW; |
17 | my $pc = new JSON::PC; |
17 | my $pc = new JSON::PC; |
18 | my $xs = JSON::XS->new->pretty (1)->canonical (1); |
18 | my $xs = JSON::XS->new->pretty->canonical->shrink; |
19 | |
19 | |
20 | my $json; # the test string |
20 | my $json; # the test string |
21 | |
21 | |
22 | local $/; |
22 | local $/; |
23 | $json = <>; |
23 | $json = <>; |
|
|
24 | |
|
|
25 | srand 0; $json = JSON::XS->new->utf8(1)->ascii(0)->encode ([join "", map +(chr rand 2555), 0..2047]); |
24 | |
26 | |
25 | #if (1) { |
27 | #if (1) { |
26 | # use Storable; |
28 | # use Storable; |
27 | # open my $fh, "<:unix", "/opt/crossfire/share/cfserver/faces" or die "$!"; |
29 | # open my $fh, "<:unix", "/opt/crossfire/share/cfserver/faces" or die "$!"; |
28 | # my $faces = Storable::thaw do { <$fh> }; |
30 | # my $faces = Storable::thaw do { <$fh> }; |
… | |
… | |
31 | # print $fh2 $json; |
33 | # print $fh2 $json; |
32 | # warn length $json; |
34 | # warn length $json; |
33 | #} |
35 | #} |
34 | |
36 | |
35 | my %tst = ( |
37 | my %tst = ( |
|
|
38 | # "JSON" => ['objToJson $perl' , 'jsonToObj $json'], |
36 | "JSON::DWIW" => ['$dwiw->to_json ($perl)', '$dwiw->from_json ($json)'], |
39 | # "JSON::DWIW" => ['$dwiw->to_json ($perl)', '$dwiw->from_json ($json)'], |
|
|
40 | # "JSON::PC" => ['$pc->convert ($perl)' , '$pc->parse ($json)'], |
37 | "JSON::Syck" => ['JSON::Syck::Dump $perl', 'JSON::Syck::Load $json'], |
41 | # "JSON::Syck" => ['JSON::Syck::Dump $perl', 'JSON::Syck::Load $json'], |
38 | "JSON::PC" => ['$pc->convert ($perl)' , '$pc->parse ($json)'], |
|
|
39 | "JSON" => ['objToJson $perl' , 'jsonToObj $json'], |
|
|
40 | "JSON::XS" => ['to_json $perl' , 'from_json $json'], |
42 | "JSON::XS" => ['to_json $perl' , 'from_json $json'], |
41 | "JSON::XS/2" => ['$xs->encode ($perl)' , '$xs->decode ($json)'], |
43 | "JSON::XS/2" => ['$xs->encode ($perl)' , '$xs->decode ($json)'], |
42 | ); |
44 | ); |
43 | |
45 | |
44 | sub bench($) { |
46 | sub bench($) { |
45 | my ($code) = @_; |
47 | my ($code) = @_; |
46 | |
48 | |
47 | my $perl = jsonToObj $json; |
49 | my $perl = jsonToObj $json; |
48 | my $count = 100; |
50 | my $count = 20; |
49 | my $times = 15; |
51 | my $times = 25; |
50 | |
52 | |
51 | my $cent = eval "sub { " . (join ";", ($code) x $count) . "}"; |
53 | my $cent = eval "sub { " . (join ";", ($code) x $count) . "}"; |
52 | $cent->(); |
54 | $cent->(); |
53 | |
55 | |
54 | my @meas; |
56 | my @meas; |