/* main */ int main() { int i; printf("Running r_alloca performance test...\n"); fflush(stdout); system("date"); r_alloca_init(); for (i=0;i<TIMES;i++) fun("food for the heap", 128); system("date"); printf("\n--\nRunning malloc performance test...\n"); system("date"); r_alloca_init(); for (i=0;i<TIMES;i++) mfun("food for the heap", 128); system("date"); printf("\n--\nRunning alloc performance test...\n"); system("date"); r_alloca_init(); for (i=0;i<TIMES;i++) afun("food for the stack", 128); system("date"); fflush(stdout); return 0; }
/* malloc */ int mfun(const char *str, int iters) { int ret; char *ptr; if (iters == 0) return 0; ptr = strdup(str); ret = mfun(ptr, iters-1); free(ptr); return ret; }
int bm_search(BM *bmp, unsigned char *y, size_t n, int (*mfun)(unsigned char *buf, size_t n, size_t pos, void *misc), void *misc) { ssize_t i, j; int c; int nm = 0; /* Searching */ j = 0; #if HEECHUL // heechul. bug found that does not check n > bmp->saved_m // ideal bug for KLEE testing? if ( n < bmp->saved_m ) return -1; #endif while (j <= n - bmp->saved_m) { for (i = bmp->saved_m - 1; i >= 0 && bmp->saved_x[i] == (bmp->icase ? tolower(y[i + j]) : y[i + j]); --i) ; if (i < 0) { if (mfun) { ++nm; c = mfun(y, n, j, misc); if (c) return (c < 0 ? c : nm); j += bmp->bmGs[0]; } else return j; } else { unsigned char c = (bmp->icase ? tolower(y[i + j]) : y[i + j]); j += MAX(bmp->bmGs[i], bmp->bmBc[c] - bmp->saved_m + 1 + i); } } return mfun == NULL ? -1 : nm; }
int bm_search(BM *bmp, unsigned char *y, size_t n, int (*mfun)(unsigned char *buf, size_t n, size_t pos, void *misc), void *misc) { ssize_t i, j; int c; int nm = 0; /* Searching */ j = 0; while (j <= n - bmp->saved_m) { for (i = bmp->saved_m - 1; i >= 0 && bmp->saved_x[i] == (bmp->icase ? tolower(y[i + j]) : y[i + j]); --i) ; if (i < 0) { if (mfun) { ++nm; c = mfun(y, n, j, misc); if (c) return (c < 0 ? c : nm); j += bmp->bmGs[0]; } else return j; } else { unsigned char c = (bmp->icase ? tolower(y[i + j]) : y[i + j]); j += MAX(bmp->bmGs[i], bmp->bmBc[c] - bmp->saved_m + 1 + i); } } return mfun == NULL ? -1 : nm; }