Okay, I did it. It took *a lot* more than just a few million iterations to get a meaningful duration tho:
Code:
#include <stdio.h>
#include <time.h>
#include <ctype.h>
int check_digit (char c) {
if ((c>='0') && (c<='9')) return 1;
return 0;
}
int main() {
int i,j,r;
double lapse;
time_t start=time(NULL), end;
for (i=0; i<50000000; i++) {
for (j=33; j<127; j++)
r=check_digit(j);
//r=isdigit(j);
}
end=time(NULL);
if (end != start) lapse=difftime(end,start);
printf("%d seconds\n",(int)lapse);
return 0;
}
The results:
"check_digit" (the classic method):
4.7 billion times took 32 seconds.
isdigit took 24 seconds.
(Fedora Core 10 on Intel "dual" 2.2Ghz, but this is not threaded...)