Perl Monk, Perl Meditation | |
PerlMonks |
Re: Compressing a set of integersby BrowserUk (Patriarch) |
on Jan 25, 2003 at 05:33 UTC ( [id://229794]=note: print w/replies, xml ) | Need Help?? |
Just storing your number in binary rather than ascii with delimiters would cut your memory requirements to about 1/3 on average. Assuming that your example is representative and your numbers will fit in 16-bits. You mentioned the figures of 50,000 sets and assuming 4 per set as shown. Instead of approx 1 MB, your down to 390k, ignoring the cost of the arrays which should be constant That's a start. Projecting the timing of the code below gives around 3 seconds to pack the 50k x 4 x 16 bits and 0.002 secs to unpack 100 lines, which comfortably fits your spec, and my machine is hardly the quickest around.
Examine what is said, not who speaks. The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.
In Section
Seekers of Perl Wisdom
|
|