https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66414
Bug ID: 66414 Summary: Regression: string::find ten times slower than strstr Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: neleai at seznam dot cz Target Milestone: --- Hi, as I seen bug with string::== being slower than using strcmp I decided to check other functions for regressions. Here string::find doesn't simply call optimized strstr and as result its ten times slower in following benchmark on my sandy bridge. #include <cstring> #include <cstdlib> #include <string> using namespace std; int main() { int i; char s[10000]; for (i = 0; i < 10000; i++) s[i] = ((unsigned) rand() % 128) + 1; s[9999] = 0; int sum = 0; std::string foo = s; std::string bar; char *needle = strdup("needle"); for (i = 0; i < 100000; i++) { needle[0] = ((unsigned) rand() % 128) + 1; #ifdef STRSTR sum += (long) strstr(s, needle); #else sum += foo.find(needle); #endif } return sum; }