[Solved] C++ why std::string is much slower than C string


Quite interesting results. I’ve re-run the benchmark on 4.8.2 20140120 and got:

strcmp : 1.938 secs
std::string.compare(const char* s) : 1.842 secs
std::string == std::string : 1.225 secs
strncmp : 2.660 secs
memcmp : 1.182 secs
std::string.compareN : 1.711 secs

strstr : 5.854 secs
memmem : 1.187 secs
std::string.find : 14.363 secs 

So std::string behaves different.
On ref-counting see Is std::string refcounted in GCC 4.x / C++11?

solved C++ why std::string is much slower than C string