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); }, });
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Serialization uncovered
by jmcnamara (Monsignor) on May 03, 2001 at 18:34 UTC |