bguiz,
I think (I don't know) that the EntrySet iteration (alternative 2) is a little more efficient, simply because it does not have a hash for each key to get its value ... Having said that, computing the hash is O (1) operation for each entry, and therefore we ONLY say O (n) throughout HashMap ... but note that this only applies to HashMap ... other Map implementations may have VERY different performance characteristics.
I really think that you will be pushing to actually NOTICE the difference in performance. If you're interested, why not set up a test script during both iteration methods?
If you donβt have a REAL one reporting a performance problem, then you are really worried about not so much ... A few ticks here and there will not affect the general usability of your program.
I believe that many, many other aspects of the code are generally more important than direct work. Of course, some blocks are "performance critical", and this is known before it is even written, it was tested without problems ... but such cases are quite rare. As a general approach, itβs better to focus on writing complete, correct, flexible, testable, reusable, readable, supported code ... CAN performance can be built later, as needed.
Version 0 should be AS SIMPLE AS POSSIBLE without any "optimizations."
corlettk Apr 29 '11 at 0:12 2011-04-29 00:12
source share