c - odds of strstr performance -


i performing few benchmarks of code, , decided use strstr performance reference point. on pc performance of scanning text of ~7mb file (preloaded ram) 10gb/sec.
strange thing when copied code of strstr function "c:\program files (x86)\microsoft visual studio 11.0\vc\crt\src\strstr.c" program, performed much worse - 650 mb/sec. code this:

char * __cdecl strstr2 (     char * str1,     const char * str2     ) {     char *cp = (char *) str1;     char *s1, *s2;      if ( !*str2 )         return((char *)str1);      while (*cp)     {         s1 = cp;         s2 = (char *) str2;          while ( *s1 && *s2 && !(*s1-*s2) )             s1++, s2++;          if (!*s2)             return(cp);          cp++;     }      return(null);  } 

compiling code in release, compiler options default, running without debugger.
difference due compiler options, or code in strstr.c not real code used in compiled crt, or else?

upd i'm using queryperformancecounter measure timing. every test repeated 500 times, after calculate average speed , start next test. (currently i'm comparing 2 tests - crt's strstr , copied strstr2)

the microsoft crt uses assembler version of strstr found in vc\crt\src\intel\strstr.asm. on system (visual studio 10.0) inner loop looks this:

loop_start:         mov     al,[esi]            ; put next char str1 al         add     esi,1               ; increment pointer in str1 in_loop:         cmp     al,dl         je      first_char_found          test    al,al               ; end of str1?         jnz     loop_start          ; no, go char str1 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -