P is for Practical | |
PerlMonks |
Re^2: Too much SQL not enough perlby EvanCarroll (Chaplain) |
on Oct 10, 2005 at 04:29 UTC ( [id://498709]=note: print w/replies, xml ) | Need Help?? |
I do not think it is fair you load up your hash prior to the benchmarking, that skews the results. Nor, is it fair that in the 'slow' one, you use a temporary array
vs
Also, if ($choices{$item}) should probably be if (exists $choices{$item}) or you will choke on 0, empty strings, and undefs. UPDATE: Nor, is a grep a good idea, quoting a passage I remember reading in perldoc perlfaq: perldoc -q unique: These are slow (grep) (checks every element even if the first matches), inefficient (same reason), and potentially buggyBut, granted it still says: Hearing the word "in" is an indication that you probably should have used a hash, not a list or array, to store your data. Hashes are designed to answer this question quickly and efficiently. Arrays aren’t. Evan Carroll www.EvanCarroll.com
In Section
Seekers of Perl Wisdom
|
|