in reply to Re: An irrational coding choice found
in thread An irrational coding choice found
True but do not forget the distribution of the keys and the size of your data set. Size may matter too! Note the following example, one single entry with a simple key
$ perl -MDevel::Size=total_size -E'$key=123;$foo{$key}=1;$foo[$key]=1; +say total_size\%foo;say total_size\@foo' 205 1080 $ perl -MDevel::Size=total_size -E'$key=123456;$foo{$key}=1;$foo[$key] +=1;say total_size\%foo;say total_size\@foo' 208 987744 $ perl -MDevel::Size=total_size -E'$key=123456789;$foo{$key}=1;$foo[$k +ey]=1;say total_size\%foo;say total_size\@foo' 211 987654408
(I consider 123 to be small). Making the "simple" key smaller might be possible in many cases, but the calculation method to getting it to "smallish" will probably defeat the gain over hashes.
To me the most important reasons to use arrays are:
- Data must stay in original order
- Data is not guaranteed to be unique
- The "target" API works only with lists/arrays
Enjoy, Have FUN! H.Merijn
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: An irrational coding choice found
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 |
In Section
Meditations