/* Copyright(c) 2002,2003 Device Drivers Limited, All rights reserved. */ /* info@devdrv.com http://www.devdrv.com/ */ #include #include #ifdef _WIN32 #include #else #include #include #endif #define NUM_X 0x8000 #define NUM_Y 0x0010 #ifdef _WIN32 long s_tick; long e_tick; #define s_getime(msg) \ {\ s_tick = GetTickCount(); \ } #define e_getime(msg) \ {\ e_tick = GetTickCount(); \ time = e_tick - s_tick; \ } #define random rand #define srandom srand #else /* !_WIN32 */ struct timezone tz; struct timeval s_tv; struct timeval e_tv; #define s_getime(msg) \ {\ gettimeofday(&s_tv, &tz); \ } #define e_getime(msg) \ {\ gettimeofday(&e_tv, &tz); \ e_tv.tv_sec -= s_tv.tv_sec; \ e_tv.tv_usec -= s_tv.tv_usec; \ if (e_tv.tv_usec < 0) { \ e_tv.tv_usec += 1000000L; \ e_tv.tv_sec--; \ } \ time = e_tv.tv_sec * 1000 + (e_tv.tv_usec + 500) / 1000; \ } unsigned long GetTickCount() {return(1L);} #endif /* _WIN32 */ typedef long COND; COND cond_array[NUM_X][NUM_Y]; int (*func_array[NUM_X][NUM_Y])(int i, int j); int result0; int result; #define P result+=cond_array[i++][j] int func_a(int i, int j) { return(cond_array[i][j]); } int func_b(int i, int j) { return(cond_array[i][j]); } int pipe_test(int max_i, int max_j, int max_k) { int i, j, k, time; result = 0; s_getime("pipe start"); for(k = 0; k < max_k; k++) for(j = 0; j < max_j; j++) for(i = 0; i < max_i; ){ /* 0 - 255 */ P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; P; } e_getime("pipe end"); result0 = result; return(time); } int loop_test(int max_i, int max_j, int max_k) { int i, j, k, time; result = 0; s_getime("loop start"); for(k = 0; k < max_k; k++) for(j = 0; j < max_j; j++) for(i = 0; i < max_i; i++) result += cond_array[i][j]; e_getime("loop end"); if (result != result0) printf("loop result error = 0x%08x\n", result); return(time); } int cond_test(int max_i, int max_j, int max_k) { int i, j, k, time; result = 0; s_getime("bool start"); for(k = 0; k < max_k; k++) for(j = 0; j < max_j; j++) for(i = 0; i < max_i; i++) if (cond_array[i][j]) result++; e_getime("cond end"); if (result != result0) printf("cond result error = 0x%08x\n", result); return(time); } int idir_test(int max_i, int max_j, int max_k) { int i, j, k, time; result = 0; s_getime("idir start"); for(k = 0; k < max_k; k++) for(j = 0; j < max_j; j++) for(i = 0; i < max_i; i++) result += (*func_array[i][j])(i, j); e_getime("idir end"); if (result != result0) printf("idir result error = 0x%08x\n", result); return(time); } void test(int x, int y, int z) { int judge; int p, l, c, i, j, time; s_getime("init start"); for(j = 0; j < y; j++){ for(i = 0; i < x; i++){ judge = random() / (RAND_MAX / 2); cond_array[i][j] = judge ? 1 : 0; func_array[i][j] = judge ? func_a : func_b; } } e_getime("init end"); p = pipe_test(x, y, z); l = loop_test(x, y, z); c = cond_test(x, y, z); i = idir_test(x, y, z); printf("%d, %d, %d, %d, %d, %d, %d, %d\n", x, y, z, time, p, l, c, i); } int main() { srandom(GetTickCount()); printf("x, y, z, random, pipe, loop, cond, idir\n"); test(0x1000, 0x1, 0x1000); test(0x2000, 0x1, 0x800); test(0x4000, 0x1, 0x400); test(0x8000, 0x1, 0x200); test(0x8000, 0x2, 0x100); test(0x8000, 0x4, 0x80); test(0x8000, 0x8, 0x40); test(0x8000, 0x10, 0x20); return(0); }