2 ms·
> Plus you're just testing the standard library implementations. If the hash lookup was the major focus for your program, you would be using a specialized hash
by JoshTriplett 13y ago
> Plus you're just testing the standard library implementations. If the hash lookup was the major focus for your program, you would be using a specialized hash map implementation.
If there's a better general-purpose hash table, the standard library hash should be using it.
(Special-purpose, sure, use a custom data structure.)
- RyanZAG 13y agoIn the case of Java, there is a lot of inefficiency in the standard hash table in the form of Entry<T, K> objects for making it a bit nicer to use. There is also a lot of extra state stored for some of the extra features offered. Everything has a cost. If you just need a straight Int->Int or Int->Object map, there are a lot of ways to make it far more efficient. The standard library doesn't contain these, because in 99% of apps, the actual performance of the hash table is a very minor part and a small bit of overhead for added convenience is worth it. However in a program where the hashmap is the key point, you'd obviously choose to optimize it to fit your goals.