c++ - Should I cache the hash code of an STL string used as a hash key? -
I have done some performance analysis on the developed software, and I have found that the url's global dictionary is "loaded" The stage takes approximately 10% of the time, the dictionary has been implemented in the form of C + + STL Stud :: map, in which the O (LG N) lookup is. I'm going to transfer it to a hash_map, which has detected the approximate time. Stale string class does not have the property of a hash code, and it certainly does not cache a hash code. This means that every lookup is required to make the hash code again.
I suspect that the hash code is worth the caching effort. This would mean that changing the many lines of code to use a new string class with the cached hash code property. Considering that the current implementation compares the log (n) string to each search, I think that per lookup is a big win to reduce it by basically using a string translucent (hash function).
Does anyone have experience caching string with hash code? Has this ever proved worth the effort?
I have no experience with caching hash codes, but I've done some work recently Which is changing from std :: map
to std :: tr1 :: unordered_map
. Two thoughts come to mind. First of all, it is trying to make a change in a relatively simple way, because it depends on your code that sometimes makes things worse before you try to optimize more , This can give you enough speed in itself, secondly, what does your profiler say about the other 90% of your initial time? Even if you have optimized global dictionary content for up to 0 times, you will do better than 10%.
Comments
Post a Comment