Last active
September 14, 2018 08:44
-
-
Save ggl/b2f8210fd6ad3f2b85c10057cb57483c to your computer and use it in GitHub Desktop.
Benchmark six Perl serializers
This file contains hidden or 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
#!/usr/bin/env perl | |
use Benchmark; | |
use CBOR::XS (); | |
use Cpanel::JSON::XS (); | |
use Data::MessagePack; | |
use JSON::XS (); | |
use Sereal::Encoder; | |
use Sereal::Decoder; | |
my $cb = CBOR::XS->new; | |
my $cj = Cpanel::JSON::XS->new; | |
my $mp = Data::MessagePack->new; | |
my $js = JSON::XS->new; | |
my $se = Sereal::Encoder->new; | |
my $sd = Sereal::Decoder->new; | |
my $data = { | |
a => 1, | |
b => 'foo', | |
c => [2, 'bar'], | |
d => { e => 3, f => 'qux' }, | |
g => undef, | |
}; | |
my $sizes = { | |
cborxs => length $cb->encode($data), | |
cjsonxs => length $cj->encode($data), | |
msgpack => length $mp->pack($data), | |
jsonxs => length $js->encode($data), | |
sereal => length $se->encode($data), | |
}; | |
Benchmark::cmpthese(0, { | |
cborxs => sub { | |
my $encoded = $cb->encode($data); | |
my $decoded = $cb->decode($encoded); | |
}, | |
cjsonxs => sub { | |
my $encoded = $cj->encode($data); | |
my $decoded = $cj->decode($encoded); | |
}, | |
msgpack => sub { | |
my $packed = $mp->pack($data); | |
my $unpacked = $mp->unpack($packed); | |
}, | |
jsonxs => sub { | |
my $encoded = $js->encode($data); | |
my $decoded = $js->decode($encoded); | |
}, | |
sereal => sub { | |
my $encoded = $se->encode($data); | |
my $decoded = $sd->decode($encoded); | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment