Using parallel hashes has the advantages of
2 hashes -- 100_000 docs/10 char names/2 numeric values ~= 14MB
Hash of 2-element arrays -- 100_000/10-char names/2 numeric values ~= 23MB.
use constant TOTAL_WORD_SCORE => 0; use constant NUMER_OF MATCHES => 1;
You pay the price for all those 2-element arrays. However, if the types of information you are going to store about each document is likely to extend, then there are rapidly diminishing returns from using parallel hashes.
By the time you get to 4 hashes -v- 1 hash of 4-element arrays, the penalty of duplicating the hash keys comes to bear with the former taking ~= 25MB and the latter ~= 30MB.
So it's easy to see that from the extensibility point of view, the HoA's comes out a winner pretty quickly and you should probably only consider the former if you're pretty certain that you won't need to extend and/or you're really up against it memory wise.
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 reply to Re: Hash of Arrays versus Two Hashes
by BrowserUk
in thread Hash of Arrays versus Two Hashes
by Cody Pendant
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |