#include #include #include #include static inline uint64_t rdtsc(void) { uint32_t lo, hi; asm volatile("lfence; rdtsc" : "=a" (lo), "=d" (hi)); return (uint64_t)hi << 32 | lo; } int main(int argc, char **argv) { uint64_t tsc0, tsc1; int ns, tsc_khz; double delta; if (argc < 2) { printf("Usage: %s \n", argv[0]); return -1; } if ((ns = atoi(argv[1])) <= 0) return -1; if ((tsc_khz = atoi(argv[2])) <= 0) return -1; tsc0 = rdtsc(); sleep(ns); tsc1 = rdtsc(); delta = tsc1 - tsc0; printf("Passed %lf s\n", delta / (tsc_khz * 1000.0)); return 0; }