Benchmark::Serialize - Benchmarks of serialization modules


Version 0.08


    use Benchmark::Serialize qw(cmpthese);

    my $structure = {
        array  => [ 'a' .. 'j' ],
        hash   => { 'a' .. 'z' },
        string => 'x' x 200,

    cmpthese( -5, $structure, qw(:core :json :yaml) );


This module encapsulates some basic benchmarks to help you choose a module for serializing data. Note that using this module is only a part of chosing a serialization format. Other factors than the benchmarked might be of relevance!

Included is support for 24 different serialization modules. Also supported is the Data::Serializer wrapper providing a unified interface for serialization and some extra features. Benchmarking of specialized modules made with Protocol Buffers for Perl/XS (protobuf-perlxs) is also available.


This module provides the following functions


Benchmark COUNT interations of a list of modules. A benchmark is either a name of a supported module, a tag, or a hash ref containing at least an inflate, a deflate, and a name attribute:

      name    => 'JSON::XS',
      deflate => sub { JSON::XS::encode_json($_[0]) }
      inflate => inflate  => sub { JSON::XS::decode_json($_[0]) }

By default Benchmark::Serialize will try to use the name attribute as a module to be loaded. This can be overridden by having a packages attribute with an arrayref containing modules to be loaded.

Benchmark tags

The following tags are supported

:all - All modules with premade benchmarks
:default - A default set of serialization modules
:core - Serialization modules included in core
:json - JSON modules
:yaml - YAML modules
:xml - XML formats


See the README file for example results.


Peter Makholm, <peter at>


Please report any bugs or feature requests to bug-benchmark-serialize at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


This module started out as a script written by Christian Hansen, see


Copyright 2009 Peter Makholm.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See for more information.