https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66416

            Bug ID: 66416
           Summary: Regression: string::find 3.5 times slower than memrchr
           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: ---

Same problem as with strstr also applies here. As we know length we could
compare that to memrchr. Again instead simply calling that an implementation is
3.5 times slower 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 < 5000000; i++) 
    {
      needle[0] = ((unsigned) rand() % 128) + 1;
#ifdef MEMRCHR
      sum += (long) memrchr(s, needle[0],9999);
#else
      sum += foo.find_last_of(needle[0]);
#endif
    }
  return sum;
}

Reply via email to