Created
July 26, 2011 23:27
-
-
Save punytan/1108351 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Benchmark for decode/encode large data structure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) }, | |
} | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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