perl: ugpraded benchmarking script. and added result to docs.

This commit is contained in:
tokuhirom 2010-09-10 20:38:37 +09:00
parent f6f675d1e1
commit 5bb8b6f16c
3 changed files with 68 additions and 9 deletions

View File

@ -5,16 +5,22 @@ use JSON::XS;
use Benchmark ':all';
use Storable;
my $a = [0..2**24];
my $a = {
"method" => "handleMessage",
"params" => [ "user1", "we were just talking" ],
"id" => undef,
"array" => [ 1, 11, 234, -5, 1e5, 1e7, 1, 0 ]
};
my $j = JSON::XS::encode_json($a);
my $m = Data::MessagePack->pack($a);
my $s = Storable::nfreeze($a);
my $s = Storable::freeze($a);
print "-- deserialize\n";
print "JSON::XS: $JSON::XS::VERSION\n";
print "Data::MessagePack: $Data::MessagePack::VERSION\n";
print "Storable: $Storable::VERSION\n";
timethese(
-1 => {
1000000 => {
json => sub { JSON::XS::decode_json($j) },
mp => sub { Data::MessagePack->unpack($m) },
storable => sub { Storable::thaw($s) },

View File

@ -5,17 +5,22 @@ use JSON::XS;
use Storable;
use Benchmark ':all';
my $a = [0..2**24];
my $a = {
"method" => "handleMessage",
"params" => [ "user1", "we were just talking" ],
"id" => undef,
"array" => [ 1, 11, 234, -5, 1e5, 1e7, 1, 0 ]
};
print "-- serialize\n";
print "JSON::XS: $JSON::XS::VERSION\n";
print "Data::MessagePack: $Data::MessagePack::VERSION\n";
print "Storable: $Storable::VERSION\n";
timethese(
-1 => {
json => sub { JSON::XS::encode_json($a) },
storable => sub { Storable::nfreeze($a) },
mp => sub { Data::MessagePack->pack($a) },
1000000 => {
json => sub { JSON::XS::encode_json($a) },
storable => sub { Storable::freeze($a) },
mp => sub { Data::MessagePack->pack($a) },
}
);

View File

@ -41,9 +41,35 @@ Data::MessagePack - MessagePack serialising/deserialising
This module converts Perl data structures to MessagePack and vice versa.
=head1 ABOUT MESSAGEPACK FORMAT
MessagePack is a binary-based efficient object serialization format.
It enables to exchange structured objects between many languages like JSON. But unlike JSON, it is very fast and small.
=head2 ADVANTAGES
=over 4
=item PORTABILITY
Messagepack is language independent binary serialize format.
=item SMALL SIZE
say length(JSON::XS::encode_json({a=>1, b=>2})); # => 13
say length(Storable::nfreeze({a=>1, b=>2})); # => 21
say length(Data::MessagePack->pack({a=>1, b=>2})); # => 7
MessagePack format saves memory than JSON and Storable format.
=item STREAMING DESERIALIZER
MessagePack supports streaming deserializer. It is useful for networking such as RPC.
=back
If you want to get more informations about messagepack format, please visit to L<http://msgpack.org/>.
=head1 METHODS
=over 4
@ -68,6 +94,28 @@ Pack the string as int when the value looks like int(EXPERIMENTAL).
=back
=head1 SPEED
This is result of benchmark/serialize.pl and benchmark/deserialize.pl on my SC440(Linux 2.6.32-23-server #37-Ubuntu SMP).
-- serialize
JSON::XS: 2.3
Data::MessagePack: 0.20
Storable: 2.21
Benchmark: timing 1000000 iterations of json, mp, storable...
json: 5 wallclock secs ( 3.95 usr + 0.00 sys = 3.95 CPU) @ 253164.56/s (n=1000000)
mp: 3 wallclock secs ( 2.69 usr + 0.00 sys = 2.69 CPU) @ 371747.21/s (n=1000000)
storable: 26 wallclock secs (27.21 usr + 0.00 sys = 27.21 CPU) @ 36751.19/s (n=1000000)
-- deserialize
JSON::XS: 2.3
Data::MessagePack: 0.20
Storable: 2.21
Benchmark: timing 1000000 iterations of json, mp, storable...
json: 4 wallclock secs ( 4.45 usr + 0.00 sys = 4.45 CPU) @ 224719.10/s (n=1000000)
mp: 6 wallclock secs ( 5.45 usr + 0.00 sys = 5.45 CPU) @ 183486.24/s (n=1000000)
storable: 7 wallclock secs ( 7.77 usr + 0.00 sys = 7.77 CPU) @ 128700.13/s (n=1000000)
=head1 AUTHORS
Tokuhiro Matsuno
@ -90,5 +138,5 @@ it under the same terms as Perl itself.
=head1 SEE ALSO
L<http://msgpack.org/>
L<http://msgpack.org/> is official web site for MessagePack format.