Why do std::string operations perform poorly?

后端 未结 12 1639
误落风尘
误落风尘 2020-12-22 23:43

I made a test to compare string operations in several languages for choosing a language for the server-side application. The results seemed normal until I finally tried C++,

12条回答
  •  借酒劲吻你
    2020-12-23 00:11

    That is the most obvious one: please try to do s.reserve(limit); before main loop.

    Documentation is here.

    I should mention that direct usage of standard classes in C++ in the same way you are used to do it in Java or Python will often give you sub-par performance if you are unaware of what is done behind the desk. There is no magical performance in language itself, it just gives you right tools.

提交回复
热议问题