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

前端 未结 6 1939
北恋
北恋 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:27

    If your in C++ 11, the copy constructor is not called unless the string is changed. Because std::string is a C++ construct, at least 1 dereference is needed to get at the string data.

    My guess would be the time is taken up in an extra dereference (which if done 10000 times is costly), and std::string is likely doing appropriate null pointer checks, which again eats up cycles.

提交回复
热议问题