Skip to content

Instantly share code, notes, and snippets.

@mlabbe
Created June 30, 2015 19:24
Show Gist options
  • Select an option

  • Save mlabbe/d3ad1f5d580351e728c0 to your computer and use it in GitHub Desktop.

Select an option

Save mlabbe/d3ad1f5d580351e728c0 to your computer and use it in GitHub Desktop.
stricmp
int ftg_stricmp(const char *s1, const char *s2)
{
int result;
const char *p1;
const char *p2;
if ( s1==s2)
return 0;
p1 = s1;
p2 = s2;
result = 0;
if ( p1 == p2 )
return result;
while (!result)
{
result = tolower(*p1) - tolower(*p2);
if ( *p1 == '\0' )
break;
++p1;
++p2;
}
return result;
}
@mlabbe

mlabbe commented Jun 30, 2015

Copy link
Copy Markdown
Author

ifdef WIN32

void perf_stricmp_w32(void)
{
const unsigned long REPS=10000000; /* default is 10mil */
char s1[] = "dogeatdogisSTORYOFMYLIFE";
char s2[] = "DOGEATDOGISSTORYOFMYLIFE";
unsigned long i;
LARGE_INTEGER frequency;
LARGE_INTEGER start;
LARGE_INTEGER end;
double interval;

printf("running perf_stricmp %lu times\n", REPS);

QueryPerformanceFrequency(&frequency);
QueryPerformanceCounter(&start);

for (i = 0; i < REPS; ++i)
{
    int result = ftg_stricmp(s1, s2);
}

QueryPerformanceCounter(&end);

interval = (double) (end.QuadPart - start.QuadPart) / frequency.QuadPart;
printf("interval: %f\n", interval);

}

endif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment