C++ map vs map performance (I know, “again?”)

前端 未结 6 1943
北恋
北恋 2020-12-24 11:05

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

6条回答
  •  孤城傲影
    2020-12-24 11:28

    You are using a const char * as a lookup key for find(). For the map containing const char* this is the correct type that find expects and the lookup can be done directly.

    The map containing std::string expects the parameter of find() to be a std::string, so in this case the const char* first has to be converted to a std::string. This is probably the difference you are seeing.

提交回复
热议问题