#define _GNU_SOURCE #include #include #include #include #include #ifndef NUM_ITER #define NUM_ITER 100000 #endif #ifndef STRING_LEN #define STRING_LEN 1000 #endif #define BUFLEN (STRING_LEN * 10 + 1) char * str_add(char *s, char *lim, const char *a) { int c; do { if (s >= lim) { s = lim - 1; c = 0; } else c = *a++; *s++ = c; } while (c); return s; } void sub_time(struct timeval *time, struct timeval *begin) { time->tv_sec -= begin->tv_sec; time->tv_usec -= begin->tv_usec; if (time->tv_usec < 0) { time->tv_usec += 1000000; --time->tv_sec; } printf("%4ld.%06ld ", time->tv_sec, time->tv_usec); } int main() { struct timeval start, end; char *buffer = (char *)alloca(BUFLEN); int i, l; char *STRING = (char *)alloca(STRING_LEN + 1); memset(STRING, '1', STRING_LEN); for(l = STRING_LEN; l >= 10; (l > 100) ? (l -= 100) : (l -= 10)) { STRING[l] = 0; // WAY1 gettimeofday(&start, NULL); for( i=0; i