Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
#!perl
# Large data structure results
# $ perl bench.pl
# 2902
# 2653
# 3941
# Benchmark: timing 500000 iterations of json decode, json encode, mp decode, mp encode, sereal decode, sereal encode...
# json decode: 22 wallclock secs (22.31 usr + 0.00 sys = 22.31 CPU) @ 22411.47/s (n=500000)
# json encode: 12 wallclock secs (10.96 usr + 0.00 sys = 10.96 CPU) @ 45620.44/s (n=500000)
# mp decode: 20 wallclock secs (20.07 usr + 0.00 sys = 20.07 CPU) @ 24912.81/s (n=500000)
# mp encode: 7 wallclock secs ( 7.41 usr + 0.00 sys = 7.41 CPU) @ 67476.38/s (n=500000)
# sereal decode: 16 wallclock secs (15.09 usr + 0.00 sys = 15.09 CPU) @ 33134.53/s (n=500000)
# sereal encode: 3 wallclock secs ( 2.74 usr + 0.00 sys = 2.74 CPU) @ 182481.75/s (n=500000)
# Small data structure results
# $ perl bench.pl
# 38
# 30
# 42
# Benchmark: timing 2000000 iterations of json decode, json encode, mp decode, mp encode, sereal decode, sereal encode...
# json decode: 1 wallclock secs ( 1.90 usr + 0.00 sys = 1.90 CPU) @ 1052631.58/s (n=2000000)
# json encode: 2 wallclock secs ( 1.63 usr + 0.00 sys = 1.63 CPU) @ 1226993.87/s (n=2000000)
# mp decode: 1 wallclock secs ( 2.38 usr + 0.00 sys = 2.38 CPU) @ 840336.13/s (n=2000000)
# mp encode: 0 wallclock secs ( 1.29 usr + 0.00 sys = 1.29 CPU) @ 1550387.60/s (n=2000000)
# sereal decode: 0 wallclock secs ( 1.62 usr + 0.00 sys = 1.62 CPU) @ 1234567.90/s (n=2000000)
# sereal encode: 0 wallclock secs ( 0.95 usr + 0.00 sys = 0.95 CPU) @ 2105263.16/s (n=2000000)
use v5.18;
use Data::MessagePack;
use Sereal;
use JSON;
use JSON::XS;
my $dt = Data::MessagePack->new;
my $srl_encoder = Sereal::Encoder->new({no_shared_hashkeys => 1});
my $srl_decoder = Sereal::Decoder->new();
# Small data structure
my %h = (
a => 1, b => 2, c => 3, d => 'string', e => 5.018,
);
# Large data structure
# my %h = (
# a => 1, b => 2, c => 3, d => 'string', e => 5.018,
# f => [map{$_} 1..1000],
# );
my $ser_sereal = Sereal::encode_sereal(\%h);
my $ser_mp = $dt->pack(\%h);
my $ser_json = JSON::encode_json(\%h);
say length($ser_sereal);
say length($ser_mp);
say length($ser_json);
use Benchmark;
Benchmark::timethese 2000000, {
'sereal encode' => sub {
$srl_encoder->encode(\%h);
},
'mp encode' => sub {
$dt->pack(\%h);
},
'json encode' => sub {
JSON::encode_json(\%h);
},
'sereal decode' => sub {
$srl_decoder->decode($ser_sereal);
},
'mp decode' => sub {
$dt->unpack($ser_mp);
},
'json decode' => sub {
JSON::decode_json($ser_json);
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.