C++ map<std::string> vs map<char *> performance (I know, “again?”)
I was using a map with a std::string key and while everything was working fine I wasn't getting the performance I expected. I searched for places to optimize and improved things only a little and that's when a colleague said, "that string key is going to be slow." I read dozens of questions and they consistently say: "don't use a char * as a key" " std::string keys are never your bottleneck" "the performance difference between a char * and a std::string is a myth." I reluctantly tried a char * key and there was a difference, a big difference. I boiled the problem down to a simple example: