/* * This little x86 app prints out the # of tight loops performed per sec, * averaged over 10 seconds. */ #include #include #include #define rdtscll(val) \ __asm__ __volatile__ ("rdtsc;" : "=A" (val)) #define SECS 10ULL int main (int argc, char **argv) { unsigned long long start, now, mhz, limit; unsigned int count; if (argc != 2) { printf("usage: loop_print \n"); exit(-1); } mhz = atol(argv[1]); limit = mhz * SECS; repeat: rdtscll(start); count = 0; /* * Just burn cycles in a tight, cached loop and measure absolute * cycles elapsed, vs. loops performed: */ for (;;) { count++; rdtscll(now); if (now - start > limit) break; } printf("userspace speed: %d loops.\n", count/SECS); fflush(stdout); goto repeat; }