Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Serialization uncovered

by gildir (Pilgrim)
on May 03, 2001 at 18:03 UTC ( [id://77655]=perlmeditation: print w/replies, xml ) Need Help??

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)
  • Dumper and DumperX are strutures serialized by Data::Dumper and deserialized by eval()
  • freeze and nfreeze are structures serialized and deserialized by Storable module
  • base64nfreeze is Storable serialized object wrapped up in MIME::Base64 encoding for storing in non-8bit-clean systems.
  • xmlDumper are structures serialized to XML document by XML::Dumper

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); }, });

Replies are listed 'Best First'.
Re: Serialization uncovered
by jmcnamara (Monsignor) on May 03, 2001 at 18:34 UTC

    There is also the Data::Denter module by Brian Ingerson of Inline fame. It is a very recent addition to CPAN.

    John.
    --

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://77655]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-16 23:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found