Created
July 28, 2010 22:22
-
-
Save dgl/496545 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
use v5.10; | |
use JSON; | |
use JSON::PP(); | |
use Data::MessagePack; | |
use MongoDB (); # For MongoDB::BSON, which needs the whole driver it seems. | |
use Storable qw(freeze thaw); | |
use Benchmark qw(cmpthese); | |
my $fat = { | |
bar => [1..500], | |
baz => { "foo" => "fooooooooooo", "ooooooooooooooooiaodi" => "ifdsoi" }, | |
b1z => { "foo" => "fooooooooooo", "ooooooooooooooooiaodi" => "ifdsoi" }, | |
b2z => { "foo" => "fooooooooooo", "ooooooooooooooooiaodi" => "ifdsoi" }, | |
b3z => { "foo" => "fooooooooooo", "ooooooooooooooooiaodi" => ("ifdsoi" x 50) }, | |
b4z => { "foo" => "fooooooooooo", "ooooooooooooooooiaodi" => "ifdsoi" }, | |
c5z => { "foo" => "fooooooooooo", "ooooooooooooooooiaodi" => "ifdsoi" }, | |
me => "alrighty then!", | |
}; | |
say "Encode"; | |
cmpthese(-1, { | |
jsonpp => sub { JSON::PP::encode_json $fat }, | |
json => sub { to_json $fat }, | |
storable => sub { freeze $fat }, | |
msgpack => sub { Data::MessagePack->pack($fat) }, | |
bson => sub { MongoDB::BSON::encode_bson($fat) }, | |
}); | |
say "Decode"; | |
$json = to_json $fat; | |
$storable = freeze $fat; | |
$msgpack = Data::MessagePack->pack($fat); | |
$bson = MongoDB::BSON::encode_bson($fat); | |
cmpthese(-1, { | |
jsonpp => sub { JSON::PP::decode_json $json }, | |
json => sub { from_json $json }, | |
storable => sub { thaw $storable }, | |
msgpack => sub { Data::MessagePack->unpack($msgpack) }, | |
bson => sub { MongoDB::BSON::decode_bson($bson) }, | |
}); | |
say "Both"; | |
cmpthese(-1, { | |
jsonpp => sub { JSON::PP::decode_json JSON::PP::encode_json $fat }, | |
json => sub { from_json to_json $fat }, | |
storable => sub { thaw freeze $fat }, | |
msgpack => sub { Data::MessagePack->unpack(Data::MessagePack->pack($fat)) }, | |
bson => sub { MongoDB::BSON::decode_bson(MongoDB::BSON::encode_bson($fat)) }, | |
}); |
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
Encode | |
Rate jsonpp bson storable json msgpack | |
jsonpp 550/s -- -75% -98% -98% -99% | |
bson 2241/s 308% -- -90% -94% -96% | |
storable 23209/s 4123% 936% -- -34% -64% | |
json 34909/s 6252% 1458% 50% -- -45% | |
msgpack 63621/s 11477% 2739% 174% 82% -- | |
Decode | |
Rate jsonpp bson json storable msgpack | |
jsonpp 182/s -- -97% -99% -99% -99% | |
bson 5338/s 2826% -- -69% -73% -75% | |
json 17230/s 9346% 223% -- -13% -20% | |
storable 19911/s 10816% 273% 16% -- -8% | |
msgpack 21557/s 11718% 304% 25% 8% -- | |
Both | |
Rate jsonpp bson storable json msgpack | |
jsonpp 139/s -- -91% -99% -99% -99% | |
bson 1569/s 1025% -- -85% -86% -90% | |
storable 10361/s 7330% 560% -- -7% -35% | |
json 11164/s 7906% 611% 8% -- -30% | |
msgpack 15905/s 11305% 914% 54% 42% -- | |
(On OS X 10.7.2, Apple's system Perl, Core i7 1.8GHz) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment