Skip to content

Instantly share code, notes, and snippets.

@punytan
Created July 26, 2011 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save punytan/1108351 to your computer and use it in GitHub Desktop.
Save punytan/1108351 to your computer and use it in GitHub Desktop.
Benchmark for decode/encode large data structure
use strict;
use warnings;
use Data::MessagePack;
use JSON;
use Storable;
use Benchmark ':all';
use HTTP::Tiny;
#$Data::MessagePack::PreferInteger = 1;
#my $a = do 'benchmark/data.pl';
my $a = JSON::decode_json(
(HTTP::Tiny->new->get('http://dist.schmorp.de/misc/json/long.json')->{content} or die "failed to fetch json file")
);
my $j = JSON::encode_json($a);
my $m = Data::MessagePack->pack($a);
my $s = Storable::freeze($a);
print "-- deserialize\n";
print "$JSON::Backend: ", $JSON::Backend->VERSION, "\n";
print "Data::MessagePack: $Data::MessagePack::VERSION\n";
print "Storable: $Storable::VERSION\n";
cmpthese timethese(
-1 => {
json => sub { JSON::decode_json($j) },
mp => sub { Data::MessagePack->unpack($m) },
storable => sub { Storable::thaw($s) },
}
);
use strict;
use warnings;
use Data::MessagePack;
use JSON;
use Storable;
use Benchmark ':all';
use HTTP::Tiny;
#my $a = do 'benchmark/data.pl';
my $a = JSON::decode_json(
(HTTP::Tiny->new->get('http://dist.schmorp.de/misc/json/long.json')->{content} or die "failed to fetch json file")
);
print "-- serialize\n";
print "$JSON::Backend: ", $JSON::Backend->VERSION, "\n";
print "Data::MessagePack: $Data::MessagePack::VERSION\n";
print "Storable: $Storable::VERSION\n";
cmpthese timethese(
-1 => {
json => sub { JSON::encode_json($a) },
storable => sub { Storable::freeze($a) },
mp => sub { Data::MessagePack->pack($a) },
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment