--- JSON-XS/eg/bench 2007/07/23 22:57:40 1.15 +++ JSON-XS/eg/bench 2010/01/19 01:02:19 1.22 @@ -2,24 +2,25 @@ # Usage: bench json-file -# which modules to test (JSON usually excluded because its so slow) +# which modules to test (JSON::PP usually excluded because its so slow) my %tst = ( -# "JSON" => ['JSON::objToJson $perl' , 'JSON::jsonToObj $json'], -# "JSON::PP" => ['$pp->encode ($perl)' , '$pp->decode ($json)'], -# "JSON::DWIW" => ['$dwiw->to_json ($perl)' , '$dwiw->from_json ($json)'], -# "JSON::PC" => ['$pc->convert ($perl)' , '$pc->parse ($json)'], -# "JSON::Syck" => ['JSON::Syck::Dump $perl' , 'JSON::Syck::Load $json'], - "JSON::XS" => ['to_json $perl' , 'from_json $json'], - "JSON::XS/2" => ['$xs2->encode ($perl)' , '$xs2->decode ($json)'], - "JSON::XS/3" => ['$xs3->encode ($perl)' , '$xs3->decode ($json)'], - "Storable" => ['Storable::nfreeze $perl' , 'Storable::thaw $pst'], +# "JSON" => ['JSON::encode_json $perl' , 'JSON::decode_json $json'], + "JSON::PP" => ['$pp->encode ($perl)' , '$pp->decode ($json)'], + "JSON::DWIW/FJ" => ['$dwiw->to_json ($perl)' , '$dwiw->from_json ($json)'], + "JSON::DWIW/DS" => ['$dwiw->to_json ($perl)' , 'JSON::DWIW::deserialize $json'], +# "JSON::PC" => ['$pc->convert ($perl)' , '$pc->parse ($json)'], + "JSON::Syck" => ['JSON::Syck::Dump $perl' , 'JSON::Syck::Load $json'], + "JSON::XS" => ['encode_json $perl' , 'decode_json $json'], + "JSON::XS/2" => ['$xs2->encode ($perl)' , '$xs2->decode ($json)'], + "JSON::XS/3" => ['$xs3->encode ($perl)' , '$xs3->decode ($json)'], + "Storable" => ['Storable::nfreeze $perl' , 'Storable::thaw $pst'], ); use JSON (); use JSON::DWIW; use JSON::PC; use JSON::PP (); -use JSON::XS qw(to_json from_json); +use JSON::XS qw(encode_json decode_json); use JSON::Syck; use Storable (); @@ -40,7 +41,7 @@ $json = <>; # fix syck-brokenised stuff -$json = JSON::XS->new->ascii(1)->encode (JSON::Syck::Load $json); +#$json = JSON::XS->new->ascii(1)->encode (JSON::Syck::Load $json); #srand 0; $json = JSON::XS->new->utf8(1)->ascii(0)->encode ([join "", map +(chr rand 255), 0..2047]); @@ -57,8 +58,8 @@ sub bench($) { my ($code) = @_; - my $perl = JSON::XS::from_json $json; - my $pst = Storable::nfreeze $perl; + my $pst = Storable::nfreeze JSON::XS::decode_json $json; # seperately decode as storable stringifies :/ + my $perl = JSON::XS::decode_json $json; my $count = 5; my $times = 200; @@ -77,13 +78,13 @@ return $count / $min; } -printf "%-10s | %10s | %10s |\n", "module", "encode", "decode"; -printf "-----------|------------|------------|\n"; +printf "%-13s | %10s | %10s |\n", "module", "encode", "decode"; +printf "--------------|------------|------------|\n"; for my $module (sort keys %tst) { my $enc = bench $tst{$module}[0]; my $dec = bench $tst{$module}[1]; - printf "%-10s | %10.3f | %10.3f |\n", $module, $enc, $dec; + printf "%-13s | %10.3f | %10.3f |\n", $module, $enc, $dec; } -printf "-----------+------------+------------+\n"; +printf "--------------+------------+------------+\n";