in reply to Re^2: string to more compact format
in thread string to more compact format
Packing the keys will make barely any difference to the storage requirements of your hash as shown below. In the first case, a hash containing 2e6 x 50-byte keys takes 70MB. In the second case, 2e6 x 12-byte keys 67MB:
$hash{ sprintf "%050d", $_ } = 1 for 0 .. 2e6;; print total_size \%hash;; 70183684 $hash{ sprintf "%012d", $_ } = 1 for 0 .. 2e6;; print total_size \%hash;; 67660852
If all you want to do is store the strings so you can iterate over them, storing the uncompressed strings in an array will save far more space (30MB versus 67/70MB):
$a[ $_ ] = sprintf "%050d", $_ for 0 .. 2e6;; print total_size \@a;; 30408448
You also save the cost of compressing and decompressing.
There are also other ways of storing and iterating your 2e6 strings that take even less memory but are just as easy and efficient to iterate.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: string to more compact format
by Boetsie (Sexton) on May 17, 2010 at 14:29 UTC | |
by BrowserUk (Patriarch) on May 17, 2010 at 14:59 UTC | |
by ack (Deacon) on May 18, 2010 at 16:31 UTC |