Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Efficient memory

by Anonymous Monk
on Nov 05, 2002 at 08:18 UTC ( [id://210408]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks I have a code like
$hash{$users}{$services}->[0];
Here i am storing the result in a MLDBM and
and the nretrieveng it later for further calculation
The problem is this is taking an awfully
lot of time just for small amounts data,
and i need to do this for larger data
any way to improve the speed would be appreciated.
I am using the Data::Dumper module
Thanks in advance

Replies are listed 'Best First'.
Re: Efficient memory
by rdfield (Priest) on Nov 05, 2002 at 09:02 UTC
    Try Storable - it stores data in a binary format which is more compact than Data::Dumper.

    Having said that, are you sure that the amount of data created by the serialisation process is what is causing the problem? There are a number of methods of checking, such as profiling.

    In short, have you definately isolated the code causing the bottlenecks or are you working on an assumption?

    rdfield

      Hi,

      actually - don't overestimate the power of Storable. Here are some benchmarks we did, because we tried to harness storables power and failed(?):

      We have a large hash. Where there is a key and the value is a list of sets of strings. We had an OLD method to store them:

      Extracting these strings (iterating the whole data structure), concatenating them in a sensible way (unique delimiters) and storing them to disk.

      And we tried a new way: Store them via Storable.

      Storable was about 7 times slower than the old method when saving the data, about 5 times faster when retrieving the data and took about 10 times more space on disk.

      For our special purposes, we decided to stick with the old method, but you may find it worth to try storable. It's way easier and consistent. On the other side - even though it saves everything in a binary form it still needs much space on disk as it saves the complete data structure too.

      You might save that space, when rebuilding that data-structure on the fly while reading the data in.

      Bye
       PetaMem

        The relevant comparison here is Storable vs. Data::Dumper. Storable is always faster than Data::Dumper.

        yes, but our large hash was currently an object and so Storable store whole object instead of the OLD method which stores only data...

Re: Efficient memory
by jlongino (Parson) on Nov 05, 2002 at 16:56 UTC
    I agree with rdfield and think that it would be worthwhile to give Storable a try. Why? because it is simple, faster than MLDBM, and you could probably write/test throwaway scripts in less than 15 minutes:
    use strict; use warnings; use Storable qw(nstore); my %data; ## sub that loads hash GetData('data.txt', \%data); ## store to disk nstore (\%data, "data.nstore");
    To retrieve:
    use strict; use warnings; use Storable qw(retrieve); my %data = %{ retrieve("data.nstore") };
    I use storable on data structures of the form data{a}{b}{c} for employee records. The flat text file is 1.5MB (5000 records), the nstored version is 3.5MB and it takes less than 2 seconds to store or retrieve. Try it and decide for yourself.

    --Jim

Re: Efficient memory
by perrin (Chancellor) on Nov 06, 2002 at 02:04 UTC
    There are large performance differences between different dbm implementions. SDBM is the fastest, so use that if your values can fit within the 2K (per hash entry) limit.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-03-29 07:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found