in reply to An irrational coding choice found
First, you should ignore AoH versus HoH, and instead concentrate of array versus hash.
If the 'keys' to your data are integers, contiguous, and smallish (or can be arranged to be smallish by the subtraction of some constant), use an array.
Because:
Vis:
$t=time; $a[ $_ ] = $_ for 1 .. 1e6; print time() - $t; print total_si +ze \@a;; 0.208095073699951 32388768 $t=time; $h{ $_ } = $_ for 1 .. 1e6; print time() - $t; print total_si +ze \%h;; 0.586999893188477 112277576
So, 60% faster and 70% less space used. (That's a single specific example, but quite typical.)
Wherever in a nested structure -- be it AoH or HoA or AoHoA .v. HoHoH -- that the keys lend themselves to the use of arrays, your code will benefit from using them in most cases.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: An irrational coding choice found
by Tux (Canon) on Mar 19, 2012 at 07:05 UTC | |
by BrowserUk (Patriarch) on Mar 19, 2012 at 07:33 UTC | |
by Tux (Canon) on Mar 19, 2012 at 09:05 UTC | |
by BrowserUk (Patriarch) on Mar 19, 2012 at 09:25 UTC | |
|
Re^2: An irrational coding choice found
by raybies (Chaplain) on Mar 21, 2012 at 14:16 UTC | |
by BrowserUk (Patriarch) on Mar 21, 2012 at 16:54 UTC | |
by jdporter (Paladin) on Mar 21, 2012 at 14:37 UTC |