use strict;
use warnings;
use JSON;
use Text::TNetstrings qw(:all);
use Benchmark qw(cmpthese);
my $structure = {
'resources' => {
'license' => [
'http://opensource.org/licenses/mit-license.php'
y $tn = encode_tnetstrings($structure);
my $json = encode_json($structure);
print "TNetstrings (" . length($tn) . ")
$tn
JSON (" . length($json) . ")
$json
";
cmpthese(-10, {
'TNetstrings' => sub{d
ecode_tnetstrings(encode_tnetstrings($structure))},
'JSON' => sub{decode_json(encode_json($structure))},
});
ification, a simple data
interchange format better suited to low-level network communication than
JSON. See http://tnetstrings.org/ for more details.
use Text::TNetstrings qw(:all);
my $data = enc
e JSON::PP;
$benchmarks{'JSON::PP'} = sub{JSON::PP::encode_json($structure)};
} or warn "Unable to require JSON::PP";
eval {
require JSON::XS;
$benchmarks{'JSON::XS'} = sub{JSON::XS::encode_json($
structure)};
} or warn "Unable to require JSON::XS";
eval {
require Convert::Bencode;
$benchmarks{'Convert::Bencode'} = sub{Convert::Bencode::bencode($structure)};
} or warn "Unable to require Conv
{
# require JSON::PP;
# $benchmarks{'JSON::PP int'} = sub{JSON::PP::encode_json("9627")};
#} or warn "Unable to require JSON::PP";
eval {
require JSON::XS;
JSON::XS->import('encode_json');
my $arr
y = encode_json(["hello", 9627]);
my $bool = "[true]";
my $float = encode_json([3.14]);
my $hash = encode_json({"hello" => 9627});
my $int = encode_json([9627]);
my $null = encode_json([undef]);
ode_json(["hello"]);
$benchmarks{'JSON::XS int'} = sub {JSON::XS::decode_json($int)};
$benchmarks{'JSON::XS bool'} = sub {JSON::XS::decode_json($bool)};
$benchmarks{'JSON::XS float'} = sub {JSON::X
equire JSON::PP;
my $encoded = JSON::PP::encode_json($structure);
$benchmarks{'JSON::PP'} = sub{JSON::PP::decode_json($encoded)};
} or warn "Unable to require JSON::PP";
eval {
require JSON::XS;
my $encoded = JSON::XS::encode_json($structure);
$benchmarks{'JSON::XS'} = sub{JSON::XS::decode_json($encoded)};
} or warn "Unable to require JSON::XS";
eval {
require Convert::Bencode;
my $encode