/* speedtest.c - speedtest */ #include #include #include #include #include #include #define N 10E6 #if defined(__i386__) static __inline__ unsigned long long cycles(void) { unsigned long long int x; __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x)); return x; } #elif defined(__x86_64__) static __inline__ unsigned long long cycles(void) { unsigned hi, lo; __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi)); return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 ); } #elif defined(__powerpc__) static __inline__ unsigned long long cycles(void) { unsigned long long int result=0; unsigned long int upper, lower,tmp; __asm__ volatile( "0: \n" "\tmftbu %0 \n" "\tmftb %1 \n" "\tmftbu %2 \n" "\tcmpw %2,%0 \n" "\tbne 0b \n" : "=r"(upper),"=r"(lower),"=r"(tmp) ); result = upper; result = result<<32; result = result|lower; return(result); } #endif int main(int argc, char **argv) { int i, attempt, t_ms; struct timeval tv_before; struct timeval tv_after; unsigned long long t_before_ms, t_after_ms; unsigned long long before_clocks, after_clocks; unsigned long long start_cycles; for (attempt=0; attempt<3;attempt++) { gettimeofday(&tv_before, NULL); before_clocks = cycles(); for(i=0; i