Fellow monks!

I've been seeking for a good way to store data in Oracle LONG column and some iteresting facts emerged to me. I've been playing with CPAN modules Data::Dumper, Storable, MIME::Base64 and XML::Dumper.
As far as user is concerned, serialization should be transparent to him. Only aspect that really matters is speed. So I've run some benchmarks no these CPAN modules:

Benchmark: timing 5000 iterations of Dumper, DumperX, base64nfreeze, f +reeze, nfreeze, xmlDumper... Dumper: 102 wallclock secs (65.65 usr + 0.13 sys = 65.78 CPU) DumperX: 34 wallclock secs (20.38 usr + 0.04 sys = 20.42 CPU) base64nfreeze: 5 wallclock secs ( 3.29 usr + 0.00 sys = 3.29 CPU) freeze: 5 wallclock secs ( 3.16 usr + 0.00 sys = 3.16 CPU) nfreeze: 5 wallclock secs ( 3.04 usr + 0.00 sys = 3.04 CPU) xmlDumper: 188 wallclock secs (116.78 usr + 0.24 sys = 117.02 CPU)

It looks like Storable is the best choice for bulk data serialization/deserialization, especialy when storing to RDBMS. MIME::Base64 should help (at little cost) when there is problem storing binary data.
DumperX function of Data::Dumper should be used when data readability and 'eval()-ability' is an issue.
XML::Dumper is here for sake of completness only. It suffers considerable overhead of XML parsing, so it should be used only when external data readability is important. But in that case, I would rather use some standard or shrink-fit XML DTD to represent data.

And to be complete, here comes snippet of my benchmark script:

use Benchmark; use Data::Dumper qw(Dumper DumperX); use Storable qw(freeze nfreeze thaw); use MIME::Base64; use XML::Dumper; use XML::Parser; my $object = { # some complex data structure here }; timethese(5000,{ 'Dumper' => sub { my $string = Dumper($object); my $obj = eval($string); }, 'DumperX' => sub { my $string = DumperX($object); my $obj = eval($string); }, 'freeze' => sub { my $string = freeze($object); my $obj = thaw($string); }, 'nfreeze' => sub { my $string = nfreeze($object); my $obj = thaw($string); }, 'base64nfreeze' => sub { my $string = encode_base64(nfreeze($object)); my $obj = thaw(decode_base64($string)); }, 'xmlDumper' => sub { my $string = XML::Dumper->pl2xml($object); my $tree = $xmlParser->parse($string); my $obj = XML::Dumper->xml2pl($tree); }, });

In reply to Serialization uncovered by gildir

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.